Why protocols
property is translated as [AnyObject] in swift, not as [P]
@protocol P;
@class C;
@interface TestGenerics: NSObject
@property NSArray<C*>* classes;
@property NSArray<P>* protocols;
@end
In Swift it look this way:
public class TestGenerics : NSObject {
public var classes: [C]
public var protocols: [AnyObject]
}
UPDATE: Found solution
@property NSArray<NSObject<P>*>* protocols;
or like suggested newacct
@property NSArray<id<P>>* protocols;
is translated to:
public var protocols: [P]
P
is not a type in Objective-C. id<P>
is an Objective-C type type for anything that conforms to the protocol P
. (NSObject<P> *
is a type for anything that is an instance of NSObject
and conforms to the protocol P
, which is slightly different condition.)
So the best way to write it would be:
@property NSArray<id<P>> *protocols;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With