My code functions properly, but I am getting warnings, so I think I can do this better. I have a subclass of NSObject (Objects) and I have a subclass of Objects (subObject). I have a property declared in subObjects. I store many objects that are all different subclasses of Objects in a single NSMutableArray. Sometimes, I go through the array and do certain things to certain objects. I read from my array like this:
//I have declared an Objects "myObject" earlier in my code.
//c is an int used to select an object from the array
myObject = [arrayObjects objectAtIndex:c];
In this case, I am accessing my property declared in subObject as
[myObject property]
The code works because I have it set up so it should not be able to get to this piece of code without being a subObject. However, I am getting a warning because the computer does not know this. It only knows that myObject is an Objects, not a subObject. How do I fix this and get rid of the warning?
If it is sure that all objects in the NSMutableArray are of type SubObject (type names should start with an upper case character), then you have these possibilities:
you can declare the item you extract as SubObject directly:
or you cast:
or you simply use id. If you use id, the compiler assumes nothing and will not issue a warning: