Realm + NSTableView + NSArrayController

流过昼夜 提交于 2019-12-07 16:50:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!