Swift: override 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 am getting the error:

Overriding method with selector "someFunction:" is of incompatible type '(NSDictionary) → AnyObject?'

How to override the method correctly?

+3


source to share


1 answer


When I try to autocomplete this class function from elsewhere in Swift, Xcode tells me what it param

is [NSObject: AnyObject]!

, what the method declaration is doing:

override class func someFunction(param: [NSObject: AnyObject]!) -> AnyObject? {
    return "Foo"
}

      



It might be a compiler error, as I'm sure I should connect to correctly NSDictionary!

(it seems to connect one way but not the other, or something like that).

+3


source







All Articles