how to override objective-c method in swift

joels

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
Mr Beardsley

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Override Objective C class method in Swift

From Dev

How to override an abstract class level method of an objective-c class in a swift class?

From Dev

how to override/swizzle a method of a private class in runtime objective-c?

From Dev

How to override private method and property from superclass in objective c

From Dev

How to override private method and property from superclass in objective c

From Dev

How I can override addTarget method of UIButton in objective c

From Dev

How to call an Objective C class method in Swift

From Dev

How to call swift method from objective c

From Dev

objective-c override system method

From Dev

Swift: Converting this Objective C Method

From Dev

How to access an Objective-C class method from Swift language

From Dev

How to call a factory method of an Objective-C class from Swift?

From Dev

How to re-write Objective C Delegate Method in Swift

From Dev

Swift: How to call a category or class method from Objective-C

From Dev

How can method in Swift with inout parameter be used in Objective-C?

From Dev

How to call an Objective-C category method in Swift

From Dev

How to translate this method from Objective-C to Swift

From Dev

How to pass a Swift struct as a parameter to an Objective-C method

From Dev

How to call Objective-C instancetype method in Swift?

From Dev

How to call an Objective-C category method in Swift

From Dev

How to call Objective-C instancetype method in Swift?

From Dev

How to call a Swift asynchronous method with closure from Objective-C

From Dev

How to implement a swift delegate method in objective-C having parameter?

From Dev

How to override objective-c project with a whole new Swift project(start over)?

From Dev

Is it safe to override a Category-defined method in Objective-C?

From Dev

Swift - Objective-C load class method?

From Dev

Swift #selector referencing to an Objective-C method

From Dev

Calling Objective - C delegate method in swift

From Dev

Swift method to return a tuple in objective c class

Related Related

  1. 1

    Override Objective C class method in Swift

  2. 2

    How to override an abstract class level method of an objective-c class in a swift class?

  3. 3

    how to override/swizzle a method of a private class in runtime objective-c?

  4. 4

    How to override private method and property from superclass in objective c

  5. 5

    How to override private method and property from superclass in objective c

  6. 6

    How I can override addTarget method of UIButton in objective c

  7. 7

    How to call an Objective C class method in Swift

  8. 8

    How to call swift method from objective c

  9. 9

    objective-c override system method

  10. 10

    Swift: Converting this Objective C Method

  11. 11

    How to access an Objective-C class method from Swift language

  12. 12

    How to call a factory method of an Objective-C class from Swift?

  13. 13

    How to re-write Objective C Delegate Method in Swift

  14. 14

    Swift: How to call a category or class method from Objective-C

  15. 15

    How can method in Swift with inout parameter be used in Objective-C?

  16. 16

    How to call an Objective-C category method in Swift

  17. 17

    How to translate this method from Objective-C to Swift

  18. 18

    How to pass a Swift struct as a parameter to an Objective-C method

  19. 19

    How to call Objective-C instancetype method in Swift?

  20. 20

    How to call an Objective-C category method in Swift

  21. 21

    How to call Objective-C instancetype method in Swift?

  22. 22

    How to call a Swift asynchronous method with closure from Objective-C

  23. 23

    How to implement a swift delegate method in objective-C having parameter?

  24. 24

    How to override objective-c project with a whole new Swift project(start over)?

  25. 25

    Is it safe to override a Category-defined method in Objective-C?

  26. 26

    Swift - Objective-C load class method?

  27. 27

    Swift #selector referencing to an Objective-C method

  28. 28

    Calling Objective - C delegate method in swift

  29. 29

    Swift method to return a tuple in objective c class

HotTag

Archive