0

What is the difference between getting and setting properties via dot notation and via sending message?

... = anObject.property;
... = [anObject property];

anObject.property = ...;
[anObject setProperty:...];

Is the dot notation only a syntactic suger for message sending and the code is compiled exactly the same or there are some differences with nil handling, performance, etc?

Maciej Jastrzebski
  • 3,457
  • 1
  • 21
  • 27

1 Answers1

4

Is the dot notation only syntactic sugar for message sending and the code is compiled exactly the same?

Yes, they're exactly the same.

  • Reason for the downvote? –  Mar 04 '13 at 19:21
  • I didnt downvote. But my guess is that probably because you didn't include any other details, somebody didn't like your answer. +1 though. – iDev Mar 04 '13 at 19:30
  • @ACB Thanks (as far as I'm concerned, there aren't "other details" - since they're exactly the same.) –  Mar 04 '13 at 19:33
  • Yes, that is true. Even I am not sure what to reply to questions which asks "Are they same?" – iDev Mar 04 '13 at 19:37
  • 2
    They aren't quite the same at compile time; the dot notation requires the left hand of the dot to be strongly typed. Minor detail; upvoted. – bbum Mar 04 '13 at 21:17
  • 1
    @bbum Thank you. Yes, that's true, I must admit. (However, if I understood correctly, OP was asking if there were any runtime differences, i. e. if they work identically.) –  Mar 05 '13 at 05:28