I just updated my xcode to 6.3.1. The problem is I got this weird error message since Swift 1.2. I got this kind of error message
/Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:32:15: Property 'self.originView' not initialized at super.init call
/Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:38:20: Immutable value 'self.originView' may only be initialized once
on this code
let originView:UIView?
override init() {
super.init() //error here
}
init(sourceView:UIView, menuItems:Array<String>){
super.init() //error here
originView = sourceView //error here
Make your
originView
nullable byIf your
originView
is not nullable you have to provide a default value before callingYou have to initialize all property before you call
super.init
in any init methodSo,change this before you call super.init()
Exception:
From Apple's “The Swift Programming Language” book:
“Swift’s compiler performs four helpful
safety-checks
to make sure that two-phase initialization is completed without error”“A designated initializer must ensure that all of the “properties introduced by its class are initialized before it delegates up to a superclass initializer.”
Basically you have to
ensure that your instance variables are in a consistent state
before you do anything, including calling methods.well in your case you can make it a new UIView:
or make it nullable
or make a lazy property instead:
when using lazy instantiation you can pass a method: