How to handle Objective-C protocols that contain properties?

后端 未结 6 1888
醉梦人生
醉梦人生 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:13

    all you have to do really is to drop a

    @synthesize title;
    

    in your implementation and you should be all set. it works the same way as just putting the property in your class interface.

    Edit:

    You may want to do this more specifically:

    @synthesize title = _title;
    

    This will fall in line with how xcode's automatic synthesis creates properties and ivars if you use auto-synthesis, so that way if your class has properties from a protocol and a class, some of your ivars won't have the different format which could impact readability.

提交回复
热议问题