B
B
balberbro2021-08-03 07:51:27
Swift
balberbro, 2021-08-03 07:51:27

How to set knowledge for Enum in structure?

I have a model

struct TimeSection: Hashable, Identifiable {
    var id: Int
    var type: SectionType
    var timerId: Int
    var fromTimestamp: Int
    var toTimestamp: Int
    
    enum SectionType: String, CaseIterable, Identifiable {
        case work = "work"
        case relax = "relax"
        
        var id: String { self.rawValue }
    }


In the view, I want to set the default value for the preview, but I don’t understand how to set the value for the type field

struct TimeSectionDetails_Previews: PreviewProvider {
    static var previews: some View {
        TimeSectionDetails(timeSection: TimeSection(
                id: 1,
                type: TimeSection.SectionType.init(rawValue: "work"), // вот тут идет ошибка, Cannon Find S in Scope
                timerId: 1,
                fromTimestamp: 1627915695,
                toTimestamp: 1627915900
            )
        )
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter Bishop, 2021-08-04
@Peter_Bishop

TimeSection.SectionType.work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question