如何在包含NSDictionary的NSArray中使用快速枚举?
我正在学习Objective C教程,并且下面的代码会将控制台切换到GDB模式。
NSMutableArray *myObjects = [NSMutableArray array];
NSArray *theObjects = [NSArray arrayWithObjects:@"easy as 1",@"easy as two", @"Easy as Three"];
NSArray *theKeys = [NSArray arrayWithObjects:@"A",@"B",@"C"];
NSDictionary *theDict = [NSDictionary dictionaryWithObjects:theObjects forKeys:theKeys];
[myObjects addObject:theDict];
for(id item in myObjects)
{
NSLog(@"Found an Item: %@",item);
}
如果我用传统的计数循环替换快速枚举循环
int count = [myObjects count];
for(int i=0;i<count;i++)
{
id item;
item = [myObjects objectAtIndex:i];
NSLog(@"Found an Item: %@",item);
}
应用程序没有崩溃,并且字典被输出到控制台窗口。这是快速枚举的限制,还是我错过了语言中的一些微妙之处?当嵌套集合时,还有其他需要注意的地方吗?
额外加分,我如何使用GDB自行调试?