私は毎回レルムエンティティに6つのオブジェクトを挿入します。通知では、私は正しい挿入を取得します。しかし私は何も修正をしないので、修正値は予期せぬものです。レルム通知ブロックは未変更の値を返します
var listNotificationToken = listResults?.addNotificationBlock({ [weak self] (changes: RealmCollectionChange) in
guard let tableView = self!.myListTableView else { return }
switch changes {
case .Initial:
tableView.reloadData()
break
case .Update(_, let deletions, let insertions, let modifications):
print("Reload - \(deletions) - \(insertions) - \(modifications)")
tableView.beginUpdates()
for insertIndex in insertions {
tableView.insertSections(NSIndexSet(index: insertIndex), withRowAnimation: .Fade)
}
for deleteIndex in deletions {
tableView.deleteSections(NSIndexSet(index: deleteIndex), withRowAnimation: .Fade)
}
for reloadIndex in modifications {
tableView.reloadSections(NSIndexSet(index: reloadIndex), withRowAnimation: .Fade)
}
tableView.endUpdates()
break
case .Error(let error):
print("\(error)")
break
}
})
結果は以下の通りである。
Reload - [] - [0, 1, 2, 3, 4, 5] - []
Reload - [] - [6, 7, 8, 9, 10, 11] - [4, 5]
Reload - [] - [12, 13, 14, 15, 16, 17] - [4, 5, 10, 11]
Reload - [] - [18, 19, 20, 21, 22, 23] - [0, 1, 6, 7, 8, 9]
Reload - [] - [24, 25, 26, 27, 28, 29] - [3, 23]
Reload - [] - [30, 31, 32, 33, 34, 35] - [0, 1, 22]
Reload - [] - [36, 37, 38, 39, 40, 41] - [0, 1, 22, 30, 31, 32, 33, 34, 35]
Reload - [] - [42, 43, 44, 45, 46, 47] - [0, 1, 22, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41]
これをデバッグするのに役立つのですか?
EDIT:
マイモデルクラス:
class TalksList: Object {
dynamic var identifier : String? = nil
dynamic var isSynced: Bool = true
dynamic var talkType : String? = nil
dynamic var title : String? = nil
...
override static func primaryKey() -> String? {
return "identifier"
}
class func saveObjectsFromArray(rawArray: NSArray) {
let dbArray = [TalksList]()
for rawObject in rawArray {
let talkListObject = TalksList()
talkListObject.isSynced = true
talkListObject.identifier = rawObject["_id"] as? String
...
dbArray.append(talkListObject)
}
try! realmInstance.write({
realmInstance.add(dbArray, update: true)
})
}
変更のコードを投稿できますか? – Idan
関連するモデルクラスも共有できますか? – bdash
@bdashモデルクラスを追加しました –