iOS automatic @synthesize without creating an ivar

后端 未结 3 1927
北恋
北恋 2020-12-09 10:59

If I have a @property which I didn\'t want to have backed via an ivar I simply omitted the @synthesize and had manual getters which re

3条回答
  •  囚心锁ツ
    2020-12-09 11:35

    Yes - iVars are still generated by clang (not Xcode, as it is the IDE, clang is the complier that really matters).

    If you really don't want iVars, and don't want an implementation, there is the somewhat archaic @dynamic keyword that will do what you want, or you can specify the property in a protocol, which doesn't make it auto-synthesized:

    // .h
    @property (nonatomic, retain) NSObject *someProp;
    
    //.m
    @dynamic someProp; // no iVars generated
    
    // other solution
    @protocol MyObjectProtcol
    
    @property (nonatomic, retain) NSObject *someProp;
    
    @end
    
    // now, when you implement the MyObjectProtocol protocol, the property won't auto-synthesize.
    

提交回复
热议问题