var Width: Int = 10
var Heigth: Int = 10
class ABC {
var A: Int = 0
var B: Int = 0
var C: Int = 0
}
var MABC = [[ABC]] (count: Width, repeatedValue: [ABC](count:Heigth, repeatedValue: ABC()))
MABC.forEach { (arr) ->() in
dump(UnsafePointer<ABC>(arr))
}
/*
▿ UnsafePointer(0x7FF4C0C36C20)
- pointerValue: 140689182780448
▿ UnsafePointer(0x7FF4C0C36C20)
- pointerValue: 140689182780448
▿ UnsafePointer(0x7FF4C0C36C20)
- pointerValue: 140689182780448
.....
*/
檢查每個元素的地址,你陣列英寸你沒有通過相同的參考陣列中的每個元素...
使用價值類型來填補你的陣列
var Width: Int = 10
var Heigth: Int = 10
struct ABC {
var A: Int = 0
var B: Int = 0
var C: Int = 0
}
var MABC = [[ABC]] (count: Width, repeatedValue: [ABC](count:Heigth, repeatedValue: ABC()))
MABC[0][0].A = 1
dump(MABC)
....▿ 10 elements
▿ [0]: 10 elements
▿ [0]: ABC
- A: 1
- B: 0
- C: 0
▿ [1]: ABC
- A: 0
- B: 0
- C: 0
▿ [2]: ABC
- A: 0
- B: 0
- C: 0
.......
這無可厚非。你用相同的參考值填充你的數組,所以數組中的所有項表示相同的類... – user3441734