Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

前端 未结 10 1230
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 06:54

I\'m currently using the iOS 5 SDK trying to develop my app. I\'m trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before wi

10条回答
  •  日久生厌
    2020-12-07 07:12

    NS_RETURNS_NOT_RETAINED is used to solve the naming problem.

    @property (nonatomic, copy) NSString *newTitle NS_RETURNS_NOT_RETAINED;
    

    We can find its definition as follows,

    #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
    

    The 'ns_returns_not_retained' attribute is the complement of 'ns_returns_retained'. Where a function or method may appear to obey the Cocoa conventions and return a retained Cocoa object, this attribute can be used to indicate that the object reference returned should not be considered as an "owning" reference being returned to the caller. The Foundation framework defines a macro NS_RETURNS_NOT_RETAINED that is functionally equivalent to the one shown below.

    Attach more details here.

提交回复
热议问题