Reputation: 220
Why the code bellow does not change the string?
class Person {
var name = "Chris"
var age = 12
var male = true
var details, = [true, 100 , "good"]
}
family().details.append("friendly")
family().details //prints [1, 100, "good"]
Upvotes: 0
Views: 57
Reputation: 5414
Because you're accessing two different objects:
family().me.append("friendly")
This line creates an object, appending "friendly" to your [Any]
family().me //prints [1, 100, "good"]
Here you're printing the contents of a brand new object: me contains only 3 elements
If you want to see the change use the same object like so:
let f = family()
f.me.append("friendly")
f.me
Upvotes: 5