我有这个for循环,完成后会给我两个string
。但是我需要将这两个string
添加到array
中。第一个string
是one
,第二个string
是two
。因此,最后,我的NSMutableArray
需要同时包含one
和two
。
如何正确执行此操作?
for (NSDictionary* dict in dictArray) {
NSString *string = ([dict valueForKey:@"string"] == [NSNull null]) ? @"" : [NSString stringWithFormat:@"%@", [dict valueForKey:@"string"]];
}
最佳答案
我也建议您简化代码
NSMutableArray *results = [NSMutableArray array];
for (NSDictionary* dict in dictArray) {
id value = dict[@"string"];
[results addObject: value == [NSNull null] ? @"" : value];
}