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

Added the ViewController Storyboard Identifiers to each storyboard #32

Closed CallumOz closed 9 years ago

CallumOz commented 9 years ago

Hi,

I modified quite a few things, the main reason was to be able to use the same ViewController class multiple times in different storyboards each with a different Storyboard ID. This was impossible before because you would end up adding an extension twice to the same class.

Now because the storyboards are structs, it means that I was able to specialise instantiateInitialViewController method so that the return type is the same as the type of the ViewController.

To instantiate a Viewcontroller with id "ListVC" in storyboard Main, you do:

let vc = Storyboards.Main.ListVC()

If you have any questions or remarks, my ears are open.

Open ears

krzyzanowskim commented 9 years ago

Related https://github.com/krzyzanowskim/Natalie/issues/27

krzyzanowskim commented 9 years ago

@CallumOz does it solve #27 ? I it is for some cases but I think (not sure) some are still not addressed - the case when the very same viewviewcotrller class is used twice in the same storyboard, with different identifiers. Correct me if I'm wrong

CallumOz commented 9 years ago

It does fix the problem in #27 even though I took a totally different approach. Since each ViewController is created using a function with the same name as the storyboard identifier, which is already unique per storyboard.

krzyzanowskim commented 9 years ago

Would you mind update README according to this changes ?

CallumOz commented 9 years ago

I have already updated the README.

krzyzanowskim commented 9 years ago

oh sorry, missed that ;) the PR looks really nice. good work!

krzyzanowskim commented 9 years ago

@CallumOz there is a problem with Example project, can you please look at it and PR the fix asap? screen shot 2015-05-27 at 14 56 13

CallumOz commented 9 years ago

Somehow I missed this. It seems that swift doesn't like functions with the same names as classes. My storyboard identifiers are generally like: MainVC or LoginVC

An easy fix is to change:

static func MainViewController() -> MainViewController! {
    return self.storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController
}

To:

static func instantiateMainViewController() -> MainViewController! {
    return self.storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController
}

If you agree with my fix, I'll add it straight away.

krzyzanowskim commented 9 years ago

We'll change that back after they fix it in Swift. The other way is use camel case for function name but nobody will find it then.

CallumOz commented 9 years ago

I think this method is probably better anyway, this way all functions for creating a ViewController start with "instantiate".