Overriding superclass initializer in Swift

Viewed 870

I've found numerous examples for using the Singleton pattern in Swift 3. I'm trying to use this method:

class Records: RailsData {
    static let shared = Records()
    private init() {} 
    ...
}

When I do, I get the compiler error:

Overriding declaration requires an 'override' keyword

When I add the override keyword, it compiles and everything seems to work. Is the override needed because I'm subclassing RailsData? RailData is an abstract class in that it is not instantiated directly. I also didn't make it a singleton.

I'm trying to make sure I don't get bit later by using the override modifier...

2 Answers

To add to @Paulo Matteo's comprehensive answer, this is most likely the fix you need:

override private init() {
    super.init()
}

Related