dot syntax vs method syntax with getter=

后端 未结 4 418
清酒与你
清酒与你 2020-12-18 23:30

I\'m not sure how much use this question is but it seems interesting to me...

I thought that using property/synthesize statements was equivalent to me creating the ge

4条回答
  •  臣服心动
    2020-12-19 00:02

    From your experiment we can infer that dot syntax is interpreted as follows:

    • is there a property with this name? If so, does it have a specified getter / setter name? if so, let's call that method.
    • otherwise, make up an appropriate method name (direct if we're getting, setXX if we're setting) and throw that at the receiver.

    You can, for example, try to use .count against an NSArray instance. Before the abomination police kick in your doors, you may have time to see that it works.

    To actually answer your question, in my mind dot notation should only be used to access properties, and in that case you should use the property name as declared in the interface. So .on for a UISwitch. I don't know why the getter name isn't given in the synthesize statement instead of the property declaration, it seems to belong in implementation rather than interface to me.

提交回复
热议问题