8
我想知道「didSet」是否適用於數組中的元組。「didSet」是否適用於數組中的元組?
我寫了類似下面的代碼,我想觀察數組內的值。它可以做這種事情嗎?
var array :[(foo: Int, bar: Int)] = []]{
didSet{
// println code
}
}
init(){
var tuple = (foo: 0, bar:0)
array = Array(count: 16, repeatedValue: tuple)
}
// change the value somewhere in the code
// and for example, want to println just only (and when) the value changed
array[3].foo = 100
謝謝你的回答! 在這段代碼中,我想打印改變的值:例如:只是數組[3] .foo。 – i77k
不客氣。 :) – Moritz
@ i77k更新了我的答案。 – Moritz