-
Notifications
You must be signed in to change notification settings - Fork 724
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
Interface Builder: Typed segues on a per scene basis #364
base: develop
Are you sure you want to change the base?
Conversation
@AliSoftware proposed another idea, that we could add to this template (or an alternative one): protocol MyViewControllerTypedStoryboardSegue {
func prepareSegueForEmbed(destination: EmbedDestinationVC)
func prepareSegueForModal(destination: ModalDestionationVC)
…
func prepare(for segue: NSStoryboardSegue, sender: Any?)
}
extension MyViewControllerTypedStoryboardSegue {
func prepare(for segue: NSStoryboardSegue, sender: Any?) {
/* generate that switch/case implementation here which calls the proper prepareSegueForXXX(destionation:) method */
}
} There could be issues here because of Another proposal was: /* Generated by SwiftGen */
protocol MyViewControllerTypedStoryboardSegue {
func prepareSegueForEmbed(destination: EmbedDestinationVC)
func prepareSegueForModal(destination: ModalDestionationVC)
…
func prepare(for segue: NSStoryboardSegue)
}
extension MyViewControllerTypedStoryboardSegue {
func prepare(for segue: NSStoryboardSegue) {
/* generate that switch/case implementation here which calls
the proper prepareSegueForXXX(destionation:) method */
}
}
/* Added by the user */
extension MyViewController: MyViewControlelrTypedStoryboardSegue {
@objc func prepare(for segue: NSStoryboardSegue, sender: Any?) {
self.prepare(for: segue)
}
} I'd probably rename the function here, because users want access to the sender argument so we'd need to pass it along. |
To know where the segues originate from would be a killer-feature for me to use SwiftGen. I have no opinion regarding the templates though. |
To begin with: any and all suggestions are welcome! You could try mock-generating the code (manually) for one of your projects (or just 1 storyboard), and see if the generated code works for you? Are all features there that you might want? Does the functionality match with your project structure? Maybe go through your project's current segues, their names and controller types, and whatever else you need when performing segues. See if there might be an issue (or not) with the generated code. |
return "/document/scenes/scene/objects/*[@sceneMemberID=\"viewController\" and @id=\"\(identifier)\"]" | ||
} | ||
static let sceneXPath = "/document/scenes/scene/objects/*[@sceneMemberID=\"viewController\"]" | ||
static let sceneSegueXPath = "//connections/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.
For my understanding, the StoryboardSegue-enum that is created inside the extensions of each custom Scene-class should only contain the segues that are started from that specific scene.
If this is the case, the xpath has to be "./connections/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.
The reason for the //
in sceneSegueXPath
is to be able to match segues started from (for example):
- container views --> embed segues
- triggered by a button or cell
sceneSegueXPath
is only used to match children of a scene object:
https://github.com/SwiftGen/SwiftGen/pull/364/files#diff-aab03c1cbf39dc54bf61cfae345dfc87R43
I made a reduced-version of your storyboard-template which contains only the scene-extensions with an segue-enum containing all segues that are started from the scene. Essentially, that is all i would need for know. You can find it here https://gist.github.com/parallaxe/7815fc6a8ed98e2e66de20d65169d608 |
02a5d87
to
7d26ace
Compare
1fc7c46
to
8db1272
Compare
69271ce
to
e75cd78
Compare
ac614c6
to
73cb682
Compare
73cb682
to
9cdaebe
Compare
9cdaebe
to
5b25491
Compare
5b25491
to
2334dd7
Compare
2334dd7
to
32d53d9
Compare
Hi all 👋 @djbe thank you for this PR! I think it would be really valuable to a lot of users. I see that you add new commits from time to time and wonder what's the state of this feature? It there anything I can do to help? 🙂 |
2564b13
to
413d0c8
Compare
eeb8043
to
68027db
Compare
11b51f9
to
24a8a3e
Compare
24a8a3e
to
1fbd5bc
Compare
1fbd5bc
to
a472128
Compare
- info about segue destinations - user defined types, and the segues starting from them
templates templates t
a472128
to
40510ef
Compare
Transfer PRs SwiftGen/SwiftGenKit#54 and SwiftGen/templates#79.
Fixes #362.
SwiftgenKit Changes
This PR improves the storyboards parser in 2 ways:
The PR also refactors the Storyboards parser a bit (split up in files).
Templates Changes
Uses the improvements added in SwiftGenKit to generate extensions for non-base classes (UIKit/AppKit), so that a user can:
For performing a segue, the user goes from:
To:
For preparing for a segue, the user goes from:
To: