Replies: 1 comment 1 reply
-
Hello (again)! I don't know if there is a direct need for them to form a kind of So, with the current state of Swift, I think your best luck is with code generation. The new version of Xcode allows build-step plugins, so it is likely that you can make this thing work even when working with packages. |
Beta Was this translation helpful? Give feedback.
-
Hello :)
When trying to perform navigation using TCA and an optional enum for the routes, as in
I've found useful and, sometimes, even necessary, to have a second enumeration mirroring
Route
, but with no associated types, andCaseIterable
. I call itRouteKey
:Route
then has a computed property that returns the key associated with a given route:This has been useful because sometimes I don't care about the child state but only that I am navigating to a specific route. Of course, I can always use
if case let .sceneC(_) = state.route
orcase .sceneD(_):
(in a switch statement) but in both cases I have to make explicit which route case I'm dealing with. With the route key and the fact that it isCaseIterable
I can perform "generic" operations that don't care about the specific route they're acting on.But it is tedious to create and maintain this second enumeration, even though the compiler is very helpful.
So, is it possible to auto-generate a
CaseIterable
enumeration of theRoute
's case names?Come to think of it, I think it would be useful also to have a way to extract the type of the associated value of each case of
Route
. Combined withCasePath
, we'd be able to go back and forth betweenRouteKey
values andCasePath
instances.Of course, none of this is specific to the
Route
enumeration. The idea is for any enumeration to automatically generate its case names and the types of their associated data.Is any of this possible without having to change the language?
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions