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 UIView
s 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:
- optional property
- property with default value
- 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
Rec iOS Conversations. Where to Start
How to Detect Whether an iOS Device Is in Silent Mode or Not
Open Viewcontroller from Tab Like in Instagram Camera Page on iOS
Hide Status Bar and Increase the Height of Uinavigationbar
How to Set Uibutton Type in Uibutton Subclass
Avplayer Uitapgesturerecognizer Not Working
Cannot Assign Class Instance to Its Protocol Type
Ios-8 and Later - Uitableview Inside an Uialertcontroller
How to Detect the Scroll Direction from the Uicollectionview
Error Using Swift - Instance Member Cannot Be Used on Type 'Viewcontroller'
Uploading Image with iOS App to Server File Size Is Too Large
Deprecated Warnings in Xcode and How to Handle Deprecation
Get the Expiration Date of a Provisioning Profile at Run-Time