有人可以解释一下以下用于填充 myStrings 数组的代码片段之间的区别:
NSString *match = @"ad*.png";
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"SELF like %@", match];
NSArray *onlyPNGs = [dirContents filteredArrayUsingPredicate:fltr];
myStrings = [NSMutableArray array];
for(int i=0;i<[onlyPNGs count];i++)
{
[myStrings addObject:(NSString *)[onlyPNGs objectAtIndex:i]];
}
NSLog([myStrings description]);
当我以这种方式填充数组时,在构造函数之后,myStrings 以某种方式变为空,但不是用过滤器填充,如果我手动添加项目一切都很好:
[myStrings addObject:@"adburgerking1.png"];
[myStrings addObject:@"adburgerking2.png"];
[myStrings addObject:@"adburgerking3.png"];
[myStrings addObject:@"addominos1.png"];
[myStrings addObject:@"admcdonalds1.png"];
[myStrings addObject:@"admcdonalds2.png"];
[myStrings addObject:@"admcdonalds3.png"];
[myStrings addObject:@"admeshuriskender1.png"];
[myStrings addObject:@"adquickchina1.png"];
[myStrings addObject:@"adsencam1.png"];
[myStrings addObject:@"adsultanahmetkoftecisi1.png"];
提前致谢!!!