Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate empty enum if section contains no constants #14

Closed
aschuch opened this issue Jan 15, 2015 · 5 comments
Closed

Generate empty enum if section contains no constants #14

aschuch opened this issue Jan 15, 2015 · 5 comments

Comments

@aschuch
Copy link

aschuch commented Jan 15, 2015

I am using some helper methods and swift extensions to work with the enums provided by SBConstants.
However, if e.g. there is no segue identifier setup in the storyboard, the generated SBConstants file omits the enum altogether.

This of course breaks any custom code that directly references the enums, e.g. SegueIdentifier.

I think it would be fine to output the empty enum in case there are no constants defined.
Any opinions?

@paulsamuels
Copy link
Owner

Can you provide an example demonstrating what you expect and what you are actually getting?

@aschuch
Copy link
Author

aschuch commented Jan 15, 2015

I have a helper that creates ViewControllers from ViewControllerStoryboardIdentifier.

extension UIStoryboard {

    class func main() -> UIStoryboard {
        return UIStoryboard(name: "Main", bundle: nil)
    }

    public func viewControllerWithID(identifier: ViewControllerStoryboardIdentifier) -> UIViewController {
        return self.instantiateViewControllerWithIdentifier(identifier.rawValue) as UIViewController
    }

}

Starting with an empty project and the above helper, use the SBConstants CLI to create an initial constants file.
Build the project.

Results:
The build fails, because SBConstants did not create a ViewControllerStoryboardIdentifier enum, simply because there are no view controllers with an identifier setup in the project yet.

Expected:
Ideally, SBConstants creates an empty ViewControllerStoryboardIdentifier enum per default.

public enum ViewControllerStoryboardIdentifier {}

However, empty enums trigger a compiler error, so we would need to come up with a default value for empty enums.

// Something like this, not sure...
public enum ViewControllerStoryboardIdentifier: String {
    case _unused = "_"
}

@paulsamuels
Copy link
Owner

This doesn't seem like a very generic use case to me. I'd be interested if anyone else has any opinions on this but I don't think the tool should generate an enum with placeholder values if nothing is found.

@aschuch
Copy link
Author

aschuch commented Jan 17, 2015

Hm, I know what you mean. I kinda pollutes the file with unnecessary boilerplate. I generally don't have a strong opinion on this, just wanted to start a discussion to see if anyone else has a similar "problem".

@paulsamuels
Copy link
Owner

Hey @aschuch doesn't look like anyone has picked up on this conversation. I'm going to close the issue but if you have any more thoughts feel free to reopen.

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

No branches or pull requests

2 participants