假設我有一個Core Data對象數組。如何重排核心數據對象數組並重新排列其在Swift 3中的Int屬性
let array = [Object1, Object2, Object3, Object4, Object5, Object6, Object7]
每個對象都有一個名爲indexValue屬性:Int64的
首先這些對象有indexValue屬性的這些值:
Object1 has indexValue = 1
Object2 has indexValue = 2
Object3 has indexValue = 3
Object4 has indexValue = 4
Object5 has indexValue = 5
Object6 has indexValue = 6
Object7 has indexValue = 7
現在讓我們說,我刪除Object3和Object6例如,和現在我的數組中的對象具有以下索引值
Object1 has indexValue = 1
Object2 has indexValue = 2
Object4 has indexValue = 4
Object5 has indexValue = 5
Object7 has indexValue = 7
刪除後,我想通過以下方式來重新排序該數組: 我想改變這個數組的indexValue屬性爲以下狀態:
Object1 has indexValue = 1
Object2 has indexValue = 2
Object4 has indexValue = 3
Object5 has indexValue = 4
Object7 has indexValue = 5
的主要困難是保持舊秩序,同時給予新的值的indexValue。我正在尋找一種算法,在Swift 3中完成這項工作。
所以,你希望indexValue獲取數組中每個對象的真實索引值? – nbloqs
@nbloqs'i ++'在Swift 3中不起作用,'indexValue'是'Int64'和基於1的。 – vadian