ps23Rick
(Rick F)
1
Hi all..
I played with Swift about 6 years ago but didn't get super deep into things and got busy with other things.. Now I've come back and a lot has changed. I'm enjoying my fiddling around with it so far and am playing around with a little experiment of my own.
I've got a category struct with a type enum and depending on the value of that enum then I'd like additional data to be available specific to the enum setting.
For instance if the enum specifies a "recurring" transaction that can be weekly, monthly or yearly I'd like fields to be available specific to the weekly or monthly or yearly if that makes sense. I think this is probably called using variants..
I did see some people talk a bit about this (link here and here) from at least 4 years ago regarding using structs + protocols to implement variants..
But I know that the language is still changing and perhaps now there's a better way in Swift -- then I'd like to give it a try..
thx in advance..
vns
2
From what I understood, you are simply need an enum with parameters:
enum Recurring {
case monthly(MonthlyParams)
case yearly(YearlyParams)
}
struct MonthlyParams {
// …
}
ps23Rick
(Rick F)
3
Hmm.. I had to look up some other examples but I think that might just work.. Thanks! Apparently I've still got tons to learn!