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?
2 Respuestas
+ 3
Can you please link your code, so I can have better view.
+ 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))