When trying to use code from ObjC in Swift, I encountered the following Swift error:
'myClass & myProtocol' cannot be used as a type conforming to protocol 'myProtocol' because 'myProtocol' has static requirements
The code looks roughly like this:
@interface FooGenericContainer <T : MyClass < MyProtocol > *> : MyClass
func asFoo() -> FooGenericContainer<MyClass & MyProtocol> { /// <-- error here
....
}
@protocol MyProtocol <NSObject, NSCopying, NSMutableCopying, AnotherProtocol>
@end
...
@protocol AnotherProtocol <NSObject, NSCopying, NSMutableCopying>
+ (NSDictionary *)method1;
@optional
+ (NSDictionary *)method2;
@end
What are "static requirements" of a protocol, are these the class methods it have?
How can I overcome this error?
Can I return FooGenericContainer
without specifying the generic type?