如果我理解你是正确的,你想写这样的东西:
id<SomeProtocol> someObject = AnotherObjectConformingThisProtocol;
Class class = [(NSObject*)SomeObject class];
if ([someObject isKindOfClass:[AnotherObjectConformingThisProtocol class]]) {}
if (class == [AnotherObjectConformingSomeProtocol class]) {}
如果不是 - 请澄清你的意思。
更新:我在另一篇文章附近阅读了您的评论并得到了它:
为您的 DataManager 和 Data 协议创建包装类:
@interface DataClass : NSObject <Data>
@end
@interface DataManagerClass : NSObject <DataManager>
@end
并使用这样的代码:
+(DataClass*) dataForName:(NSString *)name {
DataManagerClass* manager = SpecializedDataManager; // <-- which datatype does "manager" have to be?
return [[manager sharedManager] get:name]; //Getting data over a singleton of manager
}