What's the difference between dot syntax and square bracket syntax?

后端 未结 5 503
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 06:27

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.

  1. Is there a fundamen

5条回答
  •  旧时难觅i
    2020-11-27 06:58

    1) They're both message sending, just different syntax. [object message] is traditional syntax, object.message is the "dot notation", but means exactly the same thing. You can do some kinds of nesting with dot notation, but you can't do anything with methods that take complex arguments. In general, old hand Obj-C programmers don't use dot notation except for simple accessor calls. IMHO.

    2) The runtime is really smart and can figure it out on the fly. The type casting of pointers is really just a clue to the compiler to let you know when you messed up. It doesn't mean a thing (in this case) when the message is sent to the array to fetch a value.

提交回复
热议问题