+ 1

Constants never change? Correct?

22nd Sep 2016, 10:00 PM
Stephen
3 Respuestas
+ 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)
26th Sep 2016, 8:42 PM
Abdelkader Ait Assou
Abdelkader Ait Assou - avatar
0
Yeap
23rd Sep 2016, 4:26 PM
Alisson Chiquitto
Alisson Chiquitto - avatar
0
Correct
26th Sep 2016, 1:29 AM
Alex
Alex - avatar