问题
For example, I have MyFancyData
protocol. How can I specify that MyFancyDataClass property accepts only classes that conforms to this protocol.
@interface MyObject : NSObject
@property Class MyFancyDataClass;
回答1:
@property id<MyFancyData> myFancyDataClass;
回答2:
Do you mean something like this?
@interface MyObject : NSObject
@property (nonatomic, assign) Class<MyFancyData> cls;
@end
来源:https://stackoverflow.com/questions/27760662/is-it-possible-to-define-a-property-with-class-type-that-conforms-to-protocol