2009-03-17 7 views

Répondre

5

On dirait que vous cherchez quelque chose comme ceci:

NSMutableArray *array = [[NSMutableArray alloc] init]; 

while(foo) { 
    // create your string 
    [array addObject:string]; 
} 
+0

Ne pas oublier de libérer ou AutoRelease le tableau. –

0
-(NSArray*) makeArray 
{ 
    NSMutableArray* outArr = [NSMutableArray arrayWithCapacity:512]; // outArr is autoreleased 
    while(notFinished) 
    { 
     NSString* tempStr = [self makeTempString]; 
     [outArr addObject:tempStr]; // will incr retain count on tempStr 
    } 
    return [outArr copy]; // return a non-mutable copy 
} 
+0

[copie outArr] va fuir, et retournera toujours un tableau mutable – cobbal

+0

-copy ne retournera pas nécessairement un tableau mutable; il * devrait * être immuable. -mutableCopy renverrait définitivement un tableau mutable. [[copy] autorelease] est la bonne façon. –

Questions connexes