0

I have a NSTableView with bindings. Each row of the table is a Core Data Entity named Entry.

An Entry can have several CustomValue. Each CustomValue should be displayed in its own column in the Table.

I had 2 choices to model this in Core Data:

  • Choice 1: Either model a dictionary as a Transformable, where the key is the column name & the value is the CustomValue.
  • Choice 2: Either use a To-Many relation ship Entry <-->> CustomValue <--> key & value where key is a Column entity.

I chose the second solution based on this: Best practice? - Array/Dictionary as a Core Data Entity Attribute

BUT my problem is : with Choice 2, how can I bind the data to the column? With Choice 1, I could do something like this:

textField.bind(NSBindingName.value, to: cellView, withKeyPath: "objectValue.myDictionary.\(tableColumn!.identifier.rawValue).value", options: nil)

I'm currently stuck, I need to map a binding to something that would allow me to search for the proper value based on the key.

Any idea? Thanks in advance :-)

vomi
  • 993
  • 8
  • 18
  • 1
    Idea A: What if `myDictionary` is a dictionary property calculated from `customValues`? – Willeke Aug 02 '19 at 10:14
  • Idea B: Use datasource and/or delegate methods in combination with bindings. – Willeke Aug 02 '19 at 10:14
  • Idea C: Don't use bindings with this table view. – Willeke Aug 02 '19 at 10:15
  • Those are great ides, thanks! I tried Idea A but had problems with KVO notifications and was not comfortable going further. Idea B crossed my mind too but I was 'afraid' of the added complexity for sorting and maintaining the arrayController in parallel. Idea C added also a lot of work. I finally came back to Choice 1 because of the simplicity of the implementation compared to idea A, B & C. All in all, I think Idea A is the solution to this problem. – vomi Aug 02 '19 at 12:15

0 Answers0