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:
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 ()
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With