Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 483
joels Avatar asked Oct 20 '22 03:10

joels


1 Answers

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.

like image 197
Mr Beardsley Avatar answered Oct 21 '22 22:10

Mr Beardsley