我刚开始学习IOS开发。每次我运行这个程序时,控制台并不总是显示我的 NSLogs。
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:@"One"];
[items addObject:@"Two"];
[items addObject:@"Three"];
[items insertObject:@"zero" atIndex:0];
NSLog(@"Object at 0 is %@", [items objectAtIndex:0]);
NSLog(@"Object at 1 is %@", [items objectAtIndex:1]);
NSLog(@"Object at 2 is %@", [items objectAtIndex:2]);
NSLog(@"Object at 3 is %@", [items objectAtIndex:3]);
for (int i = 0; i < [items count]; i++) {
NSLog(@"%@", [items objectAtIndex:i]);
}
items = nil;
}
return 0;
}
每次运行它时,我都应该在控制台中得到它:
2012-04-11 16:29:10.419 RandomPossessions[701:403] Object at 0 is zero
2012-04-11 16:29:10.421 RandomPossessions[701:403] Object at 1 is One
2012-04-11 16:29:10.422 RandomPossessions[701:403] Object at 2 is Two
2012-04-11 16:29:10.422 RandomPossessions[701:403] Object at 3 is Three
2012-04-11 16:29:10.423 RandomPossessions[701:403] zero
2012-04-11 16:29:10.423 RandomPossessions[701:403] One
2012-04-11 16:29:10.424 RandomPossessions[701:403] Two
2012-04-11 16:29:10.424 RandomPossessions[701:403] Three
但有时它并没有全部显示出来。另一次我运行它,我可以得到:
2012-04-11 16:48:20.626 RandomPossessions[734:403] Object at 0 is zero
2012-04-11 16:48:20.628 RandomPossessions[734:403] Object at 1 is One
我必须多次运行该程序才能将完整的 NSLog 列表输出到控制台。这是一个错误,还是我做错了什么?谢谢