dot syntax vs method syntax with getter=

后端 未结 4 419
清酒与你
清酒与你 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-18 23:56

    However I am still unclear on where the "magic" wiring goes on that turns calls to myClass.on into [myClass isOn]

    The logic surely goes as follows, when compiling an obj.name in a getting context:

    if(there is an accessible @property for name in scope)
    {
       if(there is a custom getter specified)
          compile "[obj customGetter]"
       else
          compile "[obj name]"
    }
    else if (there is an an accessible instance method name in scope)
       compile "[obj name]"
    else
    {
       compile "[obj name]"
       warn obj may not respond to name
    }
    

    There are other ways a language/execution environment can handle custom getter names, but given that Obj-C puts the declaration in the header (which is public) the above is a good guess as to where the custom getter logic is performed - when compiling the call site.

提交回复
热议问题