fast enumeration for array containing different types of objects
-
13-09-2019 - |
Question
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?
Solution
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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow