joels
joels

Reputation: 7721

how to override objective-c method in swift

I am trying to override this objective-c method in a swift subclass. I keep getting compiler errors though:

From AWSMTLModel

- (instancetype)initWithDictionary:(NSDictionary *)dictionary error:(NSError **)error

Swift subclass

override func init!(dictionary dictionaryValue: [NSObject : AnyObject]!)//error: overriding declaration requires override keyword (fix it places override after func but gives same error

Upvotes: 5

Views: 1626

Answers (1)

Mr Beardsley
Mr Beardsley

Reputation: 3863

Drop the func.

override init?(withDictionary dict: [NSObject : AnyObject])

Also, I would get rid of the implicitly unwrapped optionals. If the init can fail, make it an optional. If the dictionary parameter is optional, create another convenience init that takes no parameters, but which creates a default dictionary and calls this init.

Upvotes: 3

Related Questions