Category:Films based on American novels
Category:American drama films
Category:American films
Category:Thriller films based on actual events
Category:Films directed by Doug Liman
Category:Films produced by Andrew G. Vajna
Category:Films scored by Lalo Schifrin
Category:Warner Bros. filmsQ:
Swift Array Accessor To Nullify Values
I am trying to achieve something like this, but, just to prevent an issue with the compiler not knowing whether a member has been overridden, I'm trying to use an array accessor instead:
var a: [String]!
var a2: [String]!
var a3: [String]! {
get {
return a2
}
set(newValue) {
a2 = newValue
}
}
But I'm getting an error saying a.append(...) is not a function.
So, is there a way to access a2 and assign it a different value than the one I'm getting from the array?
A:
You cannot do that in a closure, but if the array is mutable, you can
var a = ["a", "b", "c"]
var a2 = [String]()
var a3 = [String]()
a3[0] = "d"
println(a)
println(a2)
The assignment works because you are creating a copy of a2 inside the closure and assign to a3. The mutation happens outside the closure.
If you cannot change a2, you could replace the array with a dictionary. This does have some additional overhead.
var a: [String: String] = ["a": "b", "c": "d"]
var a2: [String: String] = ["a": "c", "b": "d"]
a[0] = "f"
a2[0] = "g"
println(a)
println(a2)
Dear visitor, welcome to FertilityZone.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering. be359ba680
Related links:
Comments