Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Added the ViewController Storyboard Identifiers to each storyboard #32

Merged
merged 5 commits into from May 27, 2015

Conversation

CallumOz
Copy link
Contributor

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

…iew Controllers are now all grouped in one spot.

This way View Controllers can have multiple Storyboard identifiers.
It also means we already have the correct type for the initial View Controller.
@krzyzanowskim
Copy link
Owner

Related #27

@krzyzanowskim
Copy link
Owner

@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
Copy link
Contributor Author

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
Copy link
Owner

Would you mind update README according to this changes ?

@CallumOz
Copy link
Contributor Author

I have already updated the README.

@krzyzanowskim
Copy link
Owner

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

krzyzanowskim added a commit that referenced this pull request May 27, 2015
Added the ViewController Storyboard Identifiers to each storyboard
@krzyzanowskim krzyzanowskim merged commit de9a834 into krzyzanowskim:master May 27, 2015
@krzyzanowskim krzyzanowskim mentioned this pull request May 27, 2015
@krzyzanowskim
Copy link
Owner

@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
Copy link
Contributor Author

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
Copy link
Owner

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.

@krzyzanowskim krzyzanowskim mentioned this pull request May 27, 2015
@CallumOz
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants