How to define and implement properties in protocol

前端 未结 2 1189
庸人自扰
庸人自扰 2020-12-28 18:05

I want to define one protocol with few properties and need to use those properties in another NSObject subclass. Please give me link or example code. I need that to work wit

相关标签:
2条回答
  • 2020-12-28 18:18

    @property just says to the compiler that the class is expected to define the methods to match that property.

    @protocol MyProtocol
    @property (nonatomic, readonly) id someObject;
    @property (nonatomic, getter=isAlive) BOOL alive;
    @end
    

    Anything implementing that protocol will now need to have

    - (id)someObject;
    - (BOOL)isAlive;
    - (void)setAlive:(BOOL)aBOOL;
    
    0 讨论(0)
  • 2020-12-28 18:23

    I think the things you're dealing with are primarily side effects of the introduction of Objective-C 2.0. It lets you do things like declare properties without also defining instance vars. But (as you have discovered), it is only x86_64 and post-10.5 compatible.

    0 讨论(0)
提交回复
热议问题