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

Fixes in generated enum Reusable #80

Closed binkdotli closed 8 years ago

binkdotli commented 8 years ago
krzyzanowskim commented 8 years ago

Thanks for PR. this shadowing thing, is it because enum case collide with class in some way ?

binkdotli commented 8 years ago

Yes. E.g. if we have a custom class SomeTableViewCell: UITableViewCell, which in the storyboard is identified as "SomeTableViewCell" (same identifier as class name), it will now generate:

extension SomeTableViewController { 

    enum Reusable: String, CustomStringConvertible, ReusableViewProtocol {
        case SomeTableViewCell_ = "SomeTableViewCell"

        var kind: ReusableKind? {
            switch (self) {
            case SomeTableViewCell_:
                return ReusableKind(rawValue: "tableViewCell")
            }
        }

        var viewType: UIView.Type? {
            switch (self) {
            case SomeTableViewCell_:
                return SomeTableViewCell.self
            }
        }

Before, there would be a compile error on the last return.

Using an underscore at the end of the identifier to disambiguate does not interfere with auto-completion, and the underscore is only added in the cases where the identifiers clash. Of course the user could change the identifier in the storyboard to work around the issue, but I prefer that it works without any changes.

krzyzanowskim commented 8 years ago

That's interesting case. I just don't like underscored prefix to be honest. If we'd knew the module we could use Module.SomeTableViewCell to identify the class, but we can't.

krzyzanowskim commented 8 years ago

how about if we add "ReusableCell" in place of "_" resulting SomeTableViewCellReusableCell for enum. WDYT ?