this post was submitted on 31 Jul 2024
9 points (100.0% liked)

Swift

352 readers
1 users here now

This group focus on the content related to the development of Apple Eco-system software. So feel free to share and talk about, for example;

founded 1 year ago
MODERATORS
 
top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 1 month ago

A switch statement?

[–] [email protected] 3 points 1 month ago* (last edited 1 month ago)

One option would be to use an enum with a label computed property.

enum TransitionState {
    case stageOne, stageTwo, stageThree

    var label: String {
        switch self {
             case .stageOne: "Stage one!"
             case .stageTwo: "Stage two!"
             case .stageThree: "Stage three!"
        }
    }
}
struct MyView: View {
    @State var transitionState: TransitionState = .stageOne

    var body: some View {
        Text(transitionState.label)
    }
}
[–] [email protected] 2 points 1 month ago

It looks like an enum with calculated properties would be great here.