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.messageyields the same result as[object message]. I think maybe nested messages cannot be created using the dot operator strategy?I created an
NSArrayobject, 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
myObjectisid, which means it's resolved at runtime and not compile time. I know very clearly what kind of objects are stored in myNSArray—they areNSStrings—so by changing the type ofmyObjecttoNSString * myObject, it works just fine. However, I experimented and found out thatmyObjectcan be of any type, be itNSStringorNSArrayorNSEnumerator, and any of these work just fine, perfectly iterating theNSArrayobject and yielding the same results. What's up with that?