Why Swift Array cannot be changed in didSet property observer?
1 answer
willSet
and didSet
are not called when the variable is first initialized, so normal behavior and valid for all property types does not matter.
Try this in the playground:
var intArray: [Int] = [] {
didSet {
intArray += [0]
}
}
intArray = []
intArray
the last statement shows that intArray
- [0].
Read the second post on Property Observers
+4
source to share