Property 'Self.*' Not Initialized at Super.Init Call

Error in Swift class: Property not initialized at super.init call

Quote from The Swift Programming Language, which answers your question:

“Swift’s compiler performs four helpful safety-checks to make sure
that two-phase initialization is completed without error:”

Safety check 1 “A designated initializer must ensure that all of the
“properties introduced by its class are initialized before it
delegates up to a superclass initializer.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.
https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11

swift Property not initialized at super.init call

You can fix this by adding a line to set notificationStyle to a default value in init?(coder aDecoder: NSCoder):

required init?(coder aDecoder: NSCoder) {
self.notificationStyle = .numberedSquare //<-- Here
super.init(coder: aDecoder)
setup(notificationStyle: notificationStyle)
}

You have to do this because in your declaration of notificationStyle, there's no default value and it must have a value before calling super.init. In your other initializers, you set it based on the incoming arguments.

This is an initializer that it sounds like you're not using anyway, but it is required with UIViews that we implement this required initializer.

Swift super.init() - Property not initialized at super.init call

Replace

fileprivate var directionsCompletionHandler:DirectionsCompletionHandler

with

fileprivate var directionsCompletionHandler: DirectionsCompletionHandler = nil

Property 'self.title' not initialized at super.init call in swift

init(frame :  CGRect ,title : String, recordUrl : String  , content : String) {
self.title = title
self.recordUrl = recordUrl
self.content = content
super.init(frame: frame)
}

In swift, you should init your parameter first, and then implement super.Method()

Property 'self.*' not initialized at super.init call

You have to initialize all property before you call super.init in any init method

So,change this before you call super.init()

originView = sourceView //error here

Exception:

  1. optional property
  2. property with default value
  3. lazy property

Property 'self.navigation' not initialized at super.init call

You need to change navigation to a mutable optional property, since it only gets set after the initialisation. All immutable properties (and mutable non-optional ones as well) must be set during initialisation.

So change

private unowned let navigation: UINavigationController

to

private unowned var navigation: UINavigationController?


Related Topics



Leave a reply



Submit