James Black

    James Black

    5 months ago
    In my shared subproject I have this enum. I would like to loop over it in Swift to have toggles.
    enum class ClothingTypes(val clothingLabel:String) {
        companion object {
            fun getNumberOfItems() = values().size
    This code isn't going to compile but basically how would I loop over ClothTypes and get each item in the enum? I did this on the Android side already. ClothingTypes.allCases.forEach { item in Toggle(isOn: $isPushEnable) { item.text } } This is basically what I want to do in a loop. Toggle(isOn: $isPushEnable) { Text(list.get(index: 0)!.clothingLabel) } Toggle(isOn: $isPushEnable) { Text(list.get(index: 1)!.clothingLabel) }
    I solved it by doing:
    val clothingTypeList = ClothingTypes.values().map{it.clothingLabel}
    in my shared viewmodel and then exposing that in the iosApp view model (it is basically just a pass-thru) and I can now use clothingTypeList to loop over.