Question about NSArrayController

I interested in learning more about Apple MVC. After looking over apple's doc on cocoa bindings (Cocoa Bindings I decide to write a simple one screen two columns tableview app using an NSArrayController to be able to sort on any column as well provide searching of the tableview.

Here is what I have so far:

import Cocoa

class ViewController: NSViewController {

    @IBOutlet var searchResultsController: NSArrayController!
    @IBOutlet weak var searchTextField: NSSearchField!
    
    @IBOutlet weak var nameTable: NSTableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        var personArray: NSMutableArray = dataArray()
  //        nameTable = nameArray

        }
    func dataArray()->NSMutableArray{
        let arr = NSMutableArray()
        arr.add(Person.createPerson(fName: "Bob", lName: "Comarda"))
        arr.add(Person.createPerson(fName: "John", lName: "Jones"))
        arr.add(Person.createPerson(fName: "Jane", lName: "Wereskla"))
        arr.add(Person.createPerson(fName: "Betty", lName: "Wereskla"))
        arr.add(Person.createPerson(fName: "Betty", lName: "Adams"))
        return arr
    }
        class Person:NSObject{
            var firstName:String = ""
            var lastName:String = ""
            
 class func createPerson(fName:String, lName:String)->Person{
                let person = Person()
                person.firstName = fName
                person.lastName = lName
                return person
                
            }
        // Do any additional setup after loading the view.
        
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}

I don't see how to populate my tableview with the array above. What do I need to do next?

Thanks

1 Like

I found some training in the Paul Hudson's book Hacking with macOS in the bookworm project. This looks like it is what I needed.

Terms of Service

Privacy Policy

Cookie Policy