为什么protocols
属性在swift中被翻译为[AnyObject],而不是[P]
@protocol P;
@class C;
@interface TestGenerics: NSObject
@property NSArray<C*>* classes;
@property NSArray<P>* protocols;
@end
在 Swift 中,它看起来是这样的:
public class TestGenerics : NSObject {
public var classes: [C]
public var protocols: [AnyObject]
}
更新:找到解决方案
@property NSArray<NSObject<P>*>* protocols;
或喜欢建议的 newacct
@property NSArray<id<P>>* protocols;
被翻译成:
public var protocols: [P]