+ 1
Constants never change? Correct?
3 odpowiedzi
+ 1
Yes for sure, but it depends... keep reading:
1- Consider a struct Menu.
struct Menu {
var index = 5
}
let menu: Menu = Menu()
print(menu.index) // will print 5
menu.index = 7 // will throw an error cause menu is a constant.
2- Now consider Menu is a class
class Menu {
var index = 5
}
let menu: Menu = Menu()
print(menu.index) // will print 5 as expected
menu.index = 7
print(menu.index) // will print 7 unlike when Menu was a struct.
It has with value types(structs and enums) and reference type(classes)
0
Yeap
0
Correct