Learn Courses My Dashboard

Why the button stops working on using a class

// That’s why we’re using an index based For loop.
// If you used a loop like this “for p in pizzas { }”, the struct instance would be copied into “p” for each iteration of the loop and you won’t be able to modify the copy in “p”.
for i in 0…<pizzas.count {

        // Change the topping1 property to pineapple
        pizzas[i].topping1 = "Pineapple"
    }
    The button does nothing if i use a class instead of struct in View. Can someone explain why?

this is from module 2 lesson 8 challenge

Classes are reference types whereas structures are value types.
https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html