问题
i have some Problems with my macOS Application and hope you can help me. Im pretty new on macOS so please be nice ;)
A part of the app consists of a simple NSTableView which content is binded to an NSArrayController. The NSArrayController is feeded from a realm database.
As you can see there is a checkbox for each row, which should set the bool value in the realm object.
The bindings are ok, so if I mark/unmark the checkbox it seems to try writing on the realm object. But since realm needs a active write transaction, which will not be triggered, it crashes.
My Question is: How can I write on realm objects with table view bindings ? Any ideas ?
回答1:
You could try to add the following to your model object (the Realm object) :
override func setValue(_ value: Any?, forKey key: String) {
try! realm?.write {
self.mySetValue(value, forKeyPath: key) // bug in swift preventing directly calling super here
}
}
private func mySetValue (_ value: Any?, forKeyPath key: String) {
super.setValue(value, forKey: key)
}
来源:https://stackoverflow.com/questions/41970072/realm-nstableview-nsarraycontroller