Overriding function of class Obj-c in Swift

Either I see strange behavior from Swift, or I'm doing something wrong.

Let's say you have an obj-c class called TurtleHelper that looks like this:

@interface TurtleHelper : NSObject

+(NSDictionary*)getTurtles;

@end

Then I want to override this method in Swift, so I do this:

class SwiftTurtles: TurtleHelper {

    override class func getTurtles() -> NSDictionary {
    ...
    }
}

The compiler gives me the following error:

The overriding method with the getTurtles selector is of the incompatible type '() -> NSDictionary'

What am I doing wrong?

+4
source share
1 answer

It turns out that the answer seems

override class func getTurtles() -> [NSObject : AnyObject]!

From the Apple documentation:

NSDictionary Swift, [NSObject: AnyObject]. NSDictionary Swift, Objective-C AnyObject.

: https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html

+7

All Articles