Comments (9)
I was thinking in generating a different protocol
aside from StoryboardScene
; perhaps StoryboardSegue
and generate the segue
s in there.
from swiftgen.
Yeah, I like that. But what about generated enum
s then (I'm thinking for a nice API at the call site here)?
Would there be a UIStoryboard.Name.Wizzard.Scene
enum for the scenes and a UIStoryboard.Name.Wizzard.Segue
for the segues? (That starts to be ridiculously long/deep namespacing… UIStoryboard.Name.Wizzard.Scene.CGU.viewController()
pfiew!)
Or maybe UIStoryboard.Scenes.Wizzard
and UIStoryboard.Segues.Wizzard
enums instead?
I'm thinking of what it would look like at the call site. So far I think something like this could be nice:
let vc1 = UIStoryboard.Scenes.Wizzard.CGU.viewController() // as a UIViewController
let vc2 = UIStoryboard.Scenes.Wizzard.viewController(.CGU) // same, just an alternative syntax
let vc3 = UIStoryboard.Scenes.Wizzard.passwordViewController() // typed as a XXPasswordViewController
let segue1 = UIStoryboard.Segues.Wizzard.Test.segue() // as a UIStoryboardSegue
let segue2 = UIStoryboard.Segues.Wizzard.segue(.Test) // same — alternative syntax
let segue3 = UIStoryboard.Segues.Wizzard.testSegue() // typed as a CustomStoryboardSegue
Note: The opposite would look more logical (in a hierarchical POV), like UIStoryboard.Wizzard.Scenes.CGU.viewController()
and UIStoryboard.Wizzard.Segues.testSegue()
, but that would clobber the UIStoryboard
namespace, which I want to avoid (and adding an extra scope of UIStoryboard.Name.Wizzard.Scenes.CGU.viewController()
seems way to much), whereas with the above solution, we only add 2 symbols at the root of the UIStoryboard
namespace, whatever the number of storyboards and segues we have in the project.
from swiftgen.
I think UIStoryboard.Segue.<Name>
and UIStoryboard.Scene.<Name>
makes the most sense to me.
I don't know if there's a need for helper
methods to access the segue
s other than just having the names of the available segue
on a specific Storyboard
though.
What do you think?
from swiftgen.
Yeah only having an enum
UIStoryboard.Segue.Wizzard
with the case Test
and case OtherSegueName
etc, is probably enough, the UIStoryboard.Segue.Wizzard.testSegue()
helper method are probably useless for segues as you rarely use custom subclasses for them, do you?
from swiftgen.
I rarely subclass them and even if I did there's not need to create one like that
from swiftgen.
So to be clear, it would probably look like this, right?
extension UIStoryboard {
enum Scene {
/* what is currently generated in the UIStoryboard.Name enum by the current code, like: */
enum Wizzard : String, StoryboardScene {
static let storyboardName = "Wizzard"
case CreateAccount = "CreateAccount"
static var createAccountViewController : CreateAccViewController {
return Wizzard.CreateAccount.viewController() as! CreateAccViewController
}
...
}
enum Message : String, StoryboardScene {
...
}
}
enum Segue {
enum Wizzard : String, StoryboardSegue {
case Segue1OfTheWizzardStoryboard = "Segue1"
case Segue2OfTheWizzardStoryboard = "Segue2"
}
enum Message : String, StoryboardSegue {
case Segue1OfTheMessageStoryboard = "Segue1"
}
}
}
If so, I actually wonder what the protocol StoryboardSegue
would contain? Maybe only a static func segue(identifier: Self)
to build an UIStoryboardSegue
instance from that enum, but even for that I wonder if that's even necessary, do you really instantiate UIStoryboardSegue
instances in real life? You generally only switch
on their identifier in prepareForSegue()
but not much create them yourself, so…
from swiftgen.
Yeah; I don't think that's segue(identifier:
is needed.
Exactly; I usually only need to check the segue id on the prepareForSegue()
from swiftgen.
Ok great! So I'd say forget about that StoryboardSegue
protocol for now ;)
from swiftgen.
override func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
switch UIStoryboard.Segue.Wizzard(rawValue: segue.identifier)! {
case .Segue1OfTheWizzardStoryboard
…
case .Segue2OfTheWizzardStoryboard
…
}
}
That looks nice from the call site :)
from swiftgen.
Related Issues (20)
- FatalError when trying to set Asset.color as foregroundColor into NSMutableAttributedString attribute HOT 2
- Unprintable ASCII character found in Swift Source Code HOT 1
- SVG images being ignored in assets HOT 1
- The SwiftGen configuration automatically substitutes fileprivate in the initialization of ColorAsset HOT 1
- Adding Extra parameter when running SwiftGen through Xcode HOT 1
- Error: `swiftgen.yml` is not a config file HOT 4
- String template is not able to generate a function with a string parameter and a plural int HOT 2
- Make `SwiftUI` types the default and not `UIKit` types. HOT 1
- Color Generated with SwiftUI HOT 2
- disable Font typealias? HOT 1
- Addition of .string file changes all previous strings usage HOT 1
- Ability to change Locale HOT 6
- Feature Request: Public access to either the fallback string or the ability to specify locale HOT 2
- Add ability to refer file name of JSON HOT 3
- Support for visionOS HOT 2
- Is this repo deprecated? HOT 4
- Add an XcodeBuiltToolPlugin for swiftgen HOT 5
- [Homebrew] Error: swiftgen has been disabled because it does not build! HOT 10
- Apple privacy manifest support HOT 2
- SwiftGen Errors on Swift 6 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftgen.