iosswiftxcode6.3.1

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


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

Solution

  • 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