if simpleArray has different types of objects and not just objects of type MYObject, I would expect that the loop will "skip" them;
At run time, objects are just objects. The philosophy of object oriented programming á la Objective-C/Smalltalk is that you send messages to objects and it decides what to do with them. The static type of the object is irrelevant and, in fact, unknown.
What you have asked the runtime to do is iterate through the objects in the array and send the message -myNum
to each one. It is not allowed to filter out other object types, because they might also respond to the selector e.g. you could add a category to NSString
that declares the selector.
instead, I've noticed that it converts them to a MYObject object and that makes no sense
It doesn't convert them at all, it just sends the message. If you want to stop this from crashing the application, you can do what the other answers suggest and test that you have an object of the correct class, but it might be more philosophically appropriate to test if it responds to the selector e.g.
int sumNums = 0;
for (MYObject* myObj in simpleArray) {
if ([myObj respondsToSelector: @selector(myNum)])
{
sumNums += [myObj myNum]; // Using message sytax to make it lear that properties are just messages.
}
}