开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜