In trying to replicate #6709 I'm running into what might be a related issue. This code should work, right?
Realm Results is up-to-date after adding new object
Realm Results is not updated after adding a new object when observing for changes via NotificationToken
class ViewController: UIViewController {
private var markers: Results<SongMarker>?
private var markersChangeTableUpdateNotificationToken: NotificationToken?
override func viewDidLoad() {
super.viewDidLoad()
let jsonString = "[{\"organizationShows\":[{\"id\":\"7f5cdcfa-5ff6-11ea-9e98-22000b74e21e\",\"songs\":[{\"id\":\"91a01616-6d1b-11ea-ae0e-22000b74e21e\"},{\"id\":\"09d141c8-5ff7-11ea-8c8f-22000b74e21e\"}]}],\"id\":\"00000000-5ab5-1de9-f4d1-b6b91ed1b036\"}]"
let jsonData = jsonString.data(using: .utf8)!
let jsonObject = try! JSONSerialization.jsonObject(with: jsonData, options: []) as! [[String: Any]]
DataModel.shared.importFromJSON(jsonObject)
let song = DataModel.shared.realm!.object(ofType: Song.self, forPrimaryKey: "91a01616-6d1b-11ea-ae0e-22000b74e21e")!
markers = DataModel.shared.realm?.objects(SongMarker.self).filter("ANY songs.id = %@", song.id).sorted(by: [SortDescriptor(keyPath: "time"), SortDescriptor(keyPath: "createdAt", ascending: false)])
//commenting these out fixes it
markersChangeTableUpdateNotificationToken?.invalidate()
markersChangeTableUpdateNotificationToken = markers?.observe { changes in
}
markers?.realm?.beginWrite()
let marker = SongMarker()
song.markers.insert(marker, at: 0)
print(markers?[0])
}
}
Realm framework version: 5.3.5
Realm Object Server version: ?
Xcode version: 11.6
iOS/OSX version: iOS 13.6
Dependency manager + version: CocoaPods 1.9.3
It looks like the specific circumstances that are broken are:
Should be easy to fix.
Should this be resolved in version 5.4.0? I continue to see this crash.
I forgot to actually bump the submodule pointer to pull it in. It'll be in the next release.