"Xcode cannot resolve the entered path" when binding control in xib file
Asked Answered
R

1

7

I am working on a simple Document macOS application in Xcode 9 / swift 4 using XIB for the interface.

I have a TextView, the value of which I want to bind to a variable in the File's Owner's class.

The xib file is called Document.xib, the Owner class "Document"

class Document: NSDocument {

    // Main text content
    public var text : NSAttributedString = NSAttributedString ()

}

The value binding property of the TextView looks like this: Click here to see

Now the little grey exclamation mark means that Xcode cannot resolve the entered keypath.

The debugger says that this class is not key value coding-compliant for the key text.

I do not know what that means, and I how I can fix this. As I am a newbie, please help. I'm sure it is something very simple for someone more experienced.

UPDATE: For binding purposes you need to declare the text variable as @objc dynamic, so Cocoa (Objective-C) can access it I guess:

class Document: NSDocument {

    // Main text content
    @objc dynamic var text : NSAttributedString = NSAttributedString ()

}
Roice answered 15/10, 2017 at 15:12 Comment(1)
Did that change work for you? I get the same thing even with @objc dynamicCruse
M
2

I was facing the same problem with Xcode 13 and Swift 5 and while the explanation mark is still there the "class is not key value coding-compliant for the key text." debugger error goes away with the addition of @objc:

@objc dynamic var isRunning = false
Matilda answered 18/11, 2021 at 22:31 Comment(1)
I had a similar problem, but I was missing dynamic.Malebranche

© 2022 - 2024 — McMap. All rights reserved.