-
Notifications
You must be signed in to change notification settings - Fork 736
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
Do not generate duplicate enum cases for segue IDs #43
Conversation
What about Segues that have different names but that could result in the same |
Note that this is also discussed in #7 where we discuss the various possible cases. Like:
|
Thanks a lot for pointing this out! What if we use nested enums as associated values to disambiguate? Something similar to this: /* storyboard segues:
my_orange
myorange
my_Pineapple
*/
// generated enum:
enum Fruit {
enum MyOranges: String {
case my_orange = "my_orange"
case myorange = "myorange"
}
case MyOrange(MyOranges)
case MyPineapple
func string() -> String {
switch self {
case .MyPineapple: return "my_Pineapple"
case .MyOrange(let orange): return orange.rawValue
}
}
}
let pineapple: Fruit = .MyPineapple
let orange: Fruit = .MyOrange(.my_orange) Please note that this PR solves a smaller issue that is a bit different from |
My example above would not work if segue string includes dots. |
I don't like the nested enums approach, not having all the enums of the same storyboard at the same level (some at the root and some nested) seems inconsistent, and it doesn't feel intuitive at the call site. |
@@ -66,6 +71,11 @@ public final class StoryboardParser { | |||
break; | |||
} | |||
} | |||
|
|||
private func appendSegue(segue: Segue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using a Set<Segue>
instead of a [Segue]
here, so we get that for free and won't need the appendSegue
private method then, letting that work to the Set
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed it to Set<Segue>
.
|
||
extension StoryboardParser.Segue: Equatable { } | ||
func ==(lhs: StoryboardParser.Segue, rhs: StoryboardParser.Segue) -> Bool { | ||
return lhs.segueID == rhs.segueID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels strange to only compare segueID
.
What if the user wants to create a template that use both segueID
and customClass
to generate the case
name?
Like some might prefer to have their template generating this: case {{segue.identifier|swiftIdentifier}}_{{segue.customClass|swiftIdentifier}} = {{segue.identifier}}
and thus if two segues have the same identifier but different customClass that wouldn't generate a conflict, and the user won't have the code he expect to be generated.
That's another reason why I still feel this de-duplication should append at template level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good catch. There were no mentions of customClass in default template, so I've just ignored it which is not right. I'll address this.
I think for the sake of code consistency, migrating the |
Sure, I'll update this too. |
Updated the PR according to the comments. My simple de-duplication now also takes |
Let me review that properly once I'm on my Mac before merging, but from there in GitHub LGTM ;) |
@@ -63,7 +72,7 @@ public final class StoryboardParser { | |||
case "connections": | |||
readyForConnections = false | |||
default: | |||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂 dammit Objective-C habits ^^
Hey @filwag So I reviewed that code rn and I just miss a couple of things:
|
Hi @AliSoftware, thanks for the review, I'll work on that :) |
Updated. @AliSoftware, explicit |
Merged via e85f7c1 Thanks again for your work on this! |
No description provided.