Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ()

}
like image 829
JensS Avatar asked Oct 15 '17 15:10

JensS


1 Answers

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
like image 188
MikeC Avatar answered Nov 18 '22 12:11

MikeC