Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fast enumeration for array containing different types of objects

If I have an NSMutableArray where I added objects of different classes (e.g. NSString, NSMutableString, NSProcessInfo, NSURL, NSMutableDictionary etc.) Now I want to fast enumerate this array, so I tried:

for (id *element in mutableArray){
   NSLog (@"Class Name: %@", [element class]);
   //do something else
}

I am getting a warning in Xcode saying

warning: invalid receiver type "id*"

How can I avoid this warning?

like image 325
Dev Avatar asked Sep 14 '26 02:09

Dev


1 Answers

The code is almost correct. When you use id, it's already implied to be a pointer, so you should write it as:

for (id element in mutableArray){
   NSLog (@"Class Name: %@", [element class]);
   //do something else
}
like image 90
pgb Avatar answered Sep 15 '26 23:09

pgb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!