Reputation: 2367
I have declared a class method in Objective-C:
+ (id) someFunction:(NSDictionary *)param;
When I subclass the class and override this method in Swift with this:
override class func someFunction(param : NSDictionary) -> AnyObject?
I get the error:
Overriding method with selector 'someFunction:' has incompatible type '(NSDictionary) -> AnyObject?'
How do I override the method correctly?
Upvotes: 3
Views: 1231
Reputation: 93286
When I try to autocomplete that class function from somewhere else in Swift, Xcode tells me that param
is an [NSObject: AnyObject]!
, which makes the method declaration work:
override class func someFunction(param: [NSObject: AnyObject]!) -> AnyObject? {
return "Foo"
}
This might be a compiler bug, since I'm pretty sure that's supposed to bridge properly to NSDictionary!
(it seems to be bridging one way, but not the other, or something).
Upvotes: 3