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

Conflict when Storyboard filename matches UIViewController subclass name #129

Open
yoiang opened this issue Oct 31, 2018 · 3 comments
Open

Comments

@yoiang
Copy link
Contributor

yoiang commented Oct 31, 2018

A project I am working on correlates our Storyboard file's names with the UIViewController subclass that is it's initial view controller. The result is a Storyboards.* struct that conflicts in naming with the view controller type itself:

...
    struct ExampleViewController: Storyboard {

        static let identifier = "ExampleViewController"

        static var storyboard: UIStoryboard {
            return UIStoryboard(name: self.identifier, bundle: nil)
        }

        static func instantiateExampleViewController() -> ExampleViewController {
            return self.storyboard.instantiateExampleViewController() as! ExampleViewController
        }

        static func instantiateViewController(withIdentifier identifier: String) -> UIViewController {
            return self.storyboard.instantiateViewController(withIdentifier: identifier)
        }

        static func instantiateViewController<T: UIViewController>(ofType type: T.Type) -> T? where T: IdentifiableProtocol {
            return self.storyboard.instantiateViewController(ofType: type)
        }
    }
...

I appreciate the brevity of the struct's name and appending something like "File" clutters that. On the other hand it is more explicit: these are mappings to files as much as we'd love to abstract them away.

@phimage
Copy link
Collaborator

phimage commented Nov 5, 2018

There is no compile issue?
because there is Storyboards.ExampleViewController vs ExampleViewController

The only things we can do is apply naming rules according to some options, like adding a postfix (like Storyboard) or remove some part like ViewController

What are you expected?

@yoiang
Copy link
Contributor Author

yoiang commented Nov 5, 2018

There is a compilation issue because of that conflict.

I would expect the resulting code to be an expected, consistent output, ie: not to do a different naming convention for some VCs because they conflict but not for others because they don't. Applying a naming rule or removing parts may decrease the likelihood of a conflict but it will still be a possibility.

Other possibility, with Swift we can specify the specific ExampleViewcontroller we are referencing if we know the project's module name:

...
    struct ExampleViewController: Storyboard {

...
        static func instantiateExampleViewController() -> ExampleModule.ExampleViewController {
            return self.storyboard.instantiateExampleViewController() as! ExampleModule.ExampleViewController
        }
...
    }
...

@phimage
Copy link
Collaborator

phimage commented Nov 5, 2018

so if there is a compile issue, please provide the error text or a test project
it will be easier to understand

ps: we have already discuss in an other issue about id naming. (no time to search now)

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

No branches or pull requests

2 participants