I am going through some walkthroughs fpr Objective-C and I got to many places where I raised my eyebrows. I would love to get them down.
Is there a fundamental difference in message sending and method calling? Objective-C lets me do both:
object.message
yields the same result as[object message]
. I think maybe nested messages cannot be created using the dot operator strategy?I created an
NSArray
object, now I am about to print results for this using anNSEnumerator
:id myObject = [object objectEnumerator];
in a while loop iterating and printing results. The type of
myObject
isid
, which means it's resolved at runtime and not compile time. I know very clearly what kind of objects are stored in myNSArray
—they areNSString
s—so by changing the type ofmyObject
toNSString * myObject
, it works just fine. However, I experimented and found out thatmyObject
can be of any type, be itNSString
orNSArray
orNSEnumerator
, and any of these work just fine, perfectly iterating theNSArray
object and yielding the same results. What's up with that?