Is it possible to define a property with Class type that conforms to protocol?

戏子无情 提交于 2019-12-12 15:08:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!