3

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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, thanks! I did not get any auto-complete suggestions at all, but yours does work. It's no problem to cast the param, so that is a compiler bug I can live with.
does appear to be some sort of compiler bug, am running into that a lot myself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.