dimanche 28 juillet 2019

How to fix "Result values in '? :' expression have mismatching types'"

I want to render two different HStacks depending on a value later coming from a backend

let list: [ReminderModel] = [ReminderModel(text: "Buy Bananas", closed: true), ReminderModel(text: "Meet John", closed: false), ReminderModel(text: "MMhh", closed: false), ReminderModel(text: "4", closed: false), ReminderModel(text: "5", closed: false), ReminderModel(text: "6", closed: false)]
var current: Int = 0

struct ReminderList: View {
    var body: some View {
        VStack() {
            list.count%3 == 2 ?
                HStack() {
                    Reminder(closed: list[list.count-2].closed, text: list[list.count-2].text)
                    Reminder(closed: list[list.count-1].closed, text: list[list.count-1].text)
                }
                : //Here is the error
                HStack() {
                    Reminder(closed: list[list.count-1].closed, text: list[list.count-1].text)
            }
        }
    }
}

Error:

Result values in '? :' expression have mismatching types HStack<TupleView<(Reminder, Reminder)>> and HStack<Reminder>

Aucun commentaire:

Enregistrer un commentaire