Objective-C synthesize property name overriding

前端 未结 5 481
心在旅途
心在旅途 2020-12-08 08:26

I am trying to understand the purpose of the synthesize directive with property name overriding. Say that I have an interface defined as follow:



        
5条回答
  •  时光取名叫无心
    2020-12-08 09:12

    Your understanding is incorrect. dummyLabel is the name of the property, and is not an alias for the instance variable - the instance variable is only called _dummyLabel. So the following holds for an instance of Dummy called myObject:

    • [myObject dummyLabel] works
    • myObject.dummyLabel works
    • [myObject _dummyLabel] fails
    • myObject._dummyLabel fails
    • myObject->dummyLabel fails
    • myObject->_dummyLabel depends on the visibility of the ivar (@public, @private, @protected)
    • [myObject valueForKey: @"dummyLabel"] works
    • [myObject valueForKey: @"_dummyLabel"] depends on the implementation of +accessInstanceVariablesDirectly (i.e. it will work in the default case where +accessInstanceVariablesDirectly returns YES).

提交回复
热议问题