たとえば、一連のオブジェクトNSArray
を含む があるとします。NSString
NSArray *games = [NSArray arrayWithObjects:@"Space Invaders", @"Dig Dug", @"Galaga", nil];
これを行うことの長所と短所は何ですか:
for (id object in games) {
NSLog(@"The name of the game is: %@", object);
NSLog(@"The name is %d characters long.", [object length]);
// Do some other stuff...
}
対:
for (NSString *name in games) {
NSLog(@"The name of the game is: %@", name);
NSLog(@"The name is %d characters long.", [name length]);
// Do some other stuff...
}