我已经创建了一个while循环,其中创建了临时字符串(每次执行该循环时,字符串都会更新)。如何从这些临时字符串中创建数组?
发布于 2009-03-17 12:08:02
听起来像是你在找这样的东西:
NSMutableArray *array = [[NSMutableArray alloc] init];
while(foo) {
// create your string
[array addObject:string];
}发布于 2009-03-17 12:16:45
-(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
}https://stackoverflow.com/questions/653937
复制相似问题