HomeiOS Developmentios - Learn how to go any enum that conforms to protocols...

ios – Learn how to go any enum that conforms to protocols to SwiftUI view


I’ve 3+ enums that every one conform to CaseIterable, Identifiable, CustomStringConvertible. I wish to go these enums to a SwiftUI Picker. Seeing because the code could be the identical for all of the enums I wish to simply go the enum to a customized view I’ve made. I am simply unsure methods to go the enums in a generic manner.

This is the code I’ve tried. It clearly will not compile as is.

struct EnumPickerView: View {
    var title: String
    var listItems: CaseIterable, Identifiable, CustomStringConvertible
    @Binding var pickedValue: String
    
    var physique: some View {
        Picker(title, choice: $pickedValue)  {
            ForEach(any CaseIterable.allCases) {
                Textual content($0.description)
            }
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments