Swift on a PreferencePane, with Cocoa Bindings; what am I doing wrong?

286 Views Asked by At

I'm attempting to make a clone of RCDefaultApp, because it was a great app and sadly Sierra killed it.

Most of the backend is done; I'm experimenting with the interface and there's gotta be something (or a number of things) I'm doing wrong. I've tried following several different tutorials, more or less to the letter and I just can't reproduce the expected results.

This is my preferencepane's file-owner:

import PreferencePanes

class SWDAMainPrefPane: NSPreferencePane {
    var schemesList = SchemesModel().value(forKey:"allSchemes") as! NSObject
    var internetSchemes = SchemesModel().internetSchemes
    override func mainViewDidLoad() {
        super.mainViewDidLoad()

    }
}

class SchemesModel: NSObject {
    var internetSchemes: NSObject {
        get {
        var schemes: [Scheme] = []
        var data = ["http":"Web Browser","mailto":"E-Mail","news":"News","rss":"RSS","ftp":"FTP","im":"Instant Messaging"]
        for (index, scheme) in data.enumerated() {
            schemes.append(Scheme(schemeName: scheme.key, description: scheme.value))
        }
        return schemes as! NSObject
        }
        set {}
    }
    var allSchemes: NSObject {
        get {
        var schemes = [Scheme]()
        if let schemesHandlers = LSWrappers.Schemes().copySchemesAndHandlers() {
            for scheme in Array(schemesHandlers.keys) {

                schemes.append(Scheme.init(schemeName: scheme))
            }
            NSLog(String(describing:schemes))
            return schemes as! NSObject
        }
        else { return [] as! NSObject }
        }
        set {}
    }
}

class Scheme: NSObject {
    init (schemeName: String, description: String? = nil) {

        super.init()
        self.setValue(schemeName, forKey: "schemeName")
        if let description = description {

            self.setValue(description, forKey: "schemeDescription")

        }
        else {

                self.setValue(self.getDescription(), forKey: "schemeDescription")
        }

    }
    var wrappedName: NSObject {
        get {
        return self.schemeName as! NSObject
        }
        set {}
    }
    var wrappedDescription: NSObject {
        get {
            return self.schemeDescription as! NSObject
        }
        set {}
    }
    var schemeName: NSString = ""
    var schemeDescription: NSString = ""

    func getDescription () -> NSString {

        if let schemeDescription = LSWrappers.Schemes().getNameForScheme(self.schemeName as String) {
            self.setValue(schemeDescription, forKey: "schemeDescription")
            return self.schemeDescription
        }
        else { return "" }
    }
}

Originally, I was attempting to dump the data into an NSBrowser, but there was absolutely no way I could get that to work; always crashed on runtime with "unrecognized selector sent to instance..." errors, even though I'm sure everything was connected correctly.

The wrapped properties are there because the browser expected me to bind to NSObject.

I then tried to use an NSTableView. If I try to bind to the tableview itself, I have the same issue. If I try to bind to the Column, it actually appears to work (although for some reason it insists I need to use NSString; not even String works) EXCEPT it looks like this:

PreferencePane looking like... what?

Here's what my Array Controller looks like. Array Controller Attributes Array Controller Bindings

And here's the Table View binding. Tableview column binding

0

There are 0 best solutions below