Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: overriding method with selector has incompatible type

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?

like image 324
Thomas Avatar asked Dec 18 '25 19:12

Thomas


1 Answers

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).

like image 126
Nate Cook Avatar answered Dec 21 '25 12:12

Nate Cook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!