Combine NSArrayController with NSTableview method "objectValueFor"

67 Views Asked by At

Can I use NSArrayController for my tableview , and using simultaneously this method : ?

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?

The idea behind:
I do not want to loose the benefits of the arraycontroller ( insert, update, delete ...) but I would like to have control on additional columns to display. The information inside these columns are calculated and formatted; values are coming from the array that the arraycontroller manages (Core Data).

I am afraid this is not possible because controller and tableviewfunction excludes each other ...

1

There are 1 best solutions below

0
Christian Krueger On

Thanks to Willeke, I got it made finally by using a extension for my entity.

extension ImportLog {
 
    // Splits the imported lines into individual words

    // For each entity, I split the property "line" .
    // Later, in the objc computed property, I pick column number x

    var splittedText:[String.SubSequence]{
        return(self.line!.split(separator: ";"))
    }
    
    // col1
    @objc var f1: String {
        get {
            let theColumn = 0
            var text:String = ""
            if ( splittedText.count-1 >= theColumn) {
                text = String(splittedText[theColumn])
            }
            return text
        }
        set {
            // no need to set something
        }
    }
 }

The computed property "f1" of the entity can now be bound in the XIB file by "Table Cell View.objectValue.f1"

enter image description here