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

Bug with multiple Storyboards #9

Closed CallumOz closed 9 years ago

CallumOz commented 9 years ago

I have a project with multiple Storyboard files, and for some reason, when I run the script on my project folder I get this:

//MARK: - Storyboards
enum Storyboards: String {
    case Filter = "Filter"
    case Main = "Main"
    case Results = "Results"

    private var instance:UIStoryboard {
        return UIStoryboard(name: self.rawValue, bundle: nil)
    }

    func instantiateInitialViewController() -> UIViewController? {
        switch (self) {
        case Filter:
            return self.instance.instantiateInitialViewController() as! NavigationController
        default:
            return self.instance.instantiateInitialViewController() as? UIViewController
        }
        switch (self) {
        case Main:
            return self.instance.instantiateInitialViewController() as! LoginViewController
        default:
            return self.instance.instantiateInitialViewController() as? UIViewController
        }
        switch (self) {
        case Results:
            return self.instance.instantiateInitialViewController() as! NavigationController
        default:
            return self.instance.instantiateInitialViewController() as? UIViewController
        }
    }

    func instantiateViewControllerWithIdentifier(identifier: String) -> UIViewController {
        return self.instance.instantiateViewControllerWithIdentifier(identifier) as! UIViewController
    }
}

As you can see, for some reason, it is creating one switch for each Storyboard instead of just one switch. Because of this, only the first switch is executed.

While I have your attention, it would be cool, if it was possible to instantiate an initial VC and immediately get the correct VC type, at the moment, this method only returns a UIViewController?

I am using the latest version of the script.

Callum

krzyzanowskim commented 9 years ago

thanks, looks like a bug.

Regarding returned type... I think it can be addressed (I had it in mind) but don't have it ready yet. PR is welcome anyway.