假設數組是這樣的:
NSArray * array = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:3], @"NameID", @"test1", @"Name", nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:6], @"NameID", @"test2", @"Name", nil],
nil];
可以遍歷像這樣:
NSEnumerator *enumerator = [array objectEnumerator];
id obj;
while ((obj = [enumerator nextObject]))
{
NSLog(@"NameID:[%@]; Name:[%@]",
[obj objectForKey:@"NameID"],
[obj objectForKey:@"Name"]);
}
輸出:
2010-02-04 11:41:53.266 x[8739] NameID:[3]; Name:[test1]
2010-02-04 11:41:53.267 x[8739] NameID:[6]; Name:[test2]