How to handle Objective-C protocols that contain properties?

后端 未结 6 1865
醉梦人生
醉梦人生 2020-12-07 07:56

I\'ve seen usage of Objective-C protocols get used in a fashion such as the following:

@protocol MyProtocol 

@required

@property (readonly)         


        
6条回答
  •  攒了一身酷
    2020-12-07 08:08

    Here's an example of mine that works perfectly, the protocol definition first of all:

    @class ExampleClass;
    
    @protocol ExampleProtocol
    
    @required
    
    // Properties
    @property (nonatomic, retain) ExampleClass *item;
    
    @end
    

    Below is a working example of a class supporting this protocol:

    #import 
    #import "Protocols.h"
    
    @class ExampleClass;
    
    @interface MyObject : NSObject  {
    
        // Property backing store
        ExampleClass        *item;
    
    }
    
    
    @implementation MyObject
    
    // Synthesize properties
    @synthesize item;
    
    @end
    

提交回复
热议问题