krzyzanowskim / Natalie

Natalie - Storyboard Code Generator (for Swift)
http://blog.krzyzanowskim.com/2015/04/15/natalie-storyboard-code-generator/
MIT License
1.17k stars 74 forks source link

Error: Value of optional type 'UIViewController?' not unwrapped; did you mean to use '!' or '?'? #70

Closed LukasGram closed 9 years ago

LukasGram commented 9 years ago

One of my Storyboards uses an UIViewController without any custom class. After the Storyboard.swift is generated I get the error in the following function:

static func instantiateInitialViewController() -> UIViewController {
   return self.storyboard.instantiateInitialViewController()
}

I'm using the Swift 2.0 version of Natalie.

krzyzanowskim commented 9 years ago

ah, it changes between SDK versions, and differ in iOS and Mac. Need to double check this one.

krzyzanowskim commented 9 years ago

how come hm.... it should be something like this, with as!

        static func instantiateInitialViewController() -> UINavigationController {
            return self.storyboard.instantiateInitialViewController() as! UINavigationController
        }
LukasGram commented 9 years ago

In one of my Storyboards the initial view controller is an UIViewController. But self.storyboard.instantiateInitialViewController() as! UIViewController would not make sense since instantiateInitialViewController() returns UIViewController? So it needs to look like this: self.storyboard.instantiateInitialViewController()!

Already created a pull request (#71) which should fix this.