Swift: Build succeeds, a blank app window and this message appear: Failed to set (contentViewController) user defined inspected property on (NSWindow)

Viewed 7031

I tried to create a simple Complex Number Calculator using classes. My application has compiled successfully, but when I ran it, a blank window appeared instead of a window with all my buttons, labels etc. and I got this message in the output window:

2016-03-08 22:20:42.499 Complex Numbers[30404:2328250] Failed to set (contentViewController) user defined inspected property on (NSWindow): Cannot create BOOL from object <_NSControllerObjectProxy: 0x6000000022c0> of class _NSControllerObjectProxy

This is my ViewController class code. It involves a complexNumber class, which I didn't submit here:

class ViewController: NSViewController {

    @IBOutlet var Screen: NSView!
    var a = complexNumber();

    @IBOutlet var realValue: NSTextField!

    @IBOutlet var imaginaryValue: NSTextField!

    @IBOutlet var resultLabel: NSTextField!

    @IBAction func lengthResult(sender: AnyObject) {

        let r = NSString(string: realValue.stringValue).doubleValue;
        let i = NSString(string: imaginaryValue.stringValue).doubleValue;

        a = complexNumber(real: r, imaginary: i);
        resultLabel.stringValue = String(a.trigonometric());
    }

    @IBAction func trigonometryResult(sender: AnyObject) {
        let r = NSString(string: realValue.stringValue).doubleValue;
        let i = NSString(string: imaginaryValue.stringValue).doubleValue;

        a = complexNumber(real: r, imaginary: i);
        resultLabel.stringValue = String(a.length());  
    }

    @IBAction func operation(sender: AnyObject) {
        a = complexNumber(real: NSString(string: realValue.stringValue).doubleValue, imaginary: NSString(string: imaginaryValue.stringValue).doubleValue);
        realValue.stringValue = ""
        imaginaryValue.stringValue = "";

        let b = complexNumber(real: NSString(string: realValue.stringValue).doubleValue, imaginary: NSString(string: imaginaryValue.stringValue).doubleValue)

        switch sender.stringValue {
            case "+": a = a.sum(b)
            case "-": a = a.dif(b)
            case "x": a = a.mul(b)
            case ":": a = a.div(b)
            default: a = a.sum(complexNumber())
        }
    }

    @IBAction func displayResult(sender: AnyObject) {
        resultLabel.stringValue = String("\(a.real) + i*\(a.imaginary)");
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

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

I found a similar thread here, but I don't think it's what I was looking for.

Can you help me, please?

6 Answers

Another reason - when you setup wrong binding. Example of my error:

Failed to set (contentViewController) user defined inspected property on (NSWindow): [<NSProgressIndicator 0x10111b890> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Enabled.

To solve this you need to delete the binding here: enter image description here

For me was a timing issue I guess. All begins after I added an SFAuthorizationView some days ago, and I discovered that thanks to a bug report, where also was clear that this is happening on older OSes like Sierra, but it is fine, instead, in 10.13+. Moving some code from viewDidLoad() to viewDidAppear() the problem gone. Basically I'm just waiting to call any related method of the problematic view later the viewcontroller content view is declared as loaded. Clearly a an Apple problem fixed in new OSes. So after instantiate the nib/xib/storyboard involved I think anyone encounter problems like that should firstly show the view and then customise it. Just my testimony.

This happens when there is an error or exception in ViewDidLoad. Ensure that error is cleared and your UI will load fine and u wont get this message.

Related