0

Swift, Instance of a Structure Property

The lesson states "When creating an instance of a structure, if you assign an instance of a structure to a constant, the instance's properties cannot be modified, even if they were declared as variable properties." But I am able to modify the property that was declared as a variable, can anybody elaborate more on what is exactly that cannot de modified even if it is declared as a variable?

27th Nov 2019, 2:35 PM
Andres Faria
Andres Faria - avatar
2 Respostas
+ 3
Can you please link your code, so I can have better view.
27th Nov 2019, 4:35 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
I just tried it, but it is giving me immutable error struct Point { var x = 0.0 func isToTheRight(x: Double) -> Bool { return self.x > x } } let p = Point() p.x = 5 print(p.isToTheRight(x: 1.1))
27th Nov 2019, 4:34 PM
Raj Chhatrala
Raj Chhatrala - avatar