Enumerating a NSArray of different objects
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"Hello World!", [NSURL URLWithString:@"http://www.apple.com"], nil];
for (id *object in array) {
NSLo开发者_开发百科g(@"Class name: %@", [object className]);
}
Given the above array of varying objects what is the proper way to fast enumerate thru them? Using the above code I do see my log statement properly, but Xcode does complain with the following message
Invalid receiver type 'id*' on my NSLog statement.
That should be:
for (id object in array) {
// ...
That is because id
already is a pointer, see the section on id
in Apples The Objective-C Programming Language for details on it.
精彩评论