I was trying to follow instructions from Learning Swift book (creating note taking app) by B.A. Paris & Co, but faced with the following problem with binding. I am mostly practicing iOS programming, so binding concept is new for me.
Steps I made (tried both xcode 9 beta 5 and 8.3.3):
And I see exclamation mark with notion “Xcode cannot resolve the entered key path” Build is successful, but when I run it says “2017-09-03 22:17:40.739643+0200 test3[6017:424072] [<test3.Document 0x6180000c3410> valueForUndefinedKey:]: this class is not key value coding-compliant for the key text.”
I tried to control drag from Xib to Swift, it warns that “Xcode cannot locate the class Document in the current workspace”.
I tried to convert to workspace instead of proj, checked the file owner, checked the stackoverflow threads witch relate to the error – but they mostly concerned about some connection made by mistake or non actual connections (I can delete the connection, I know what connection is wrong, the question is how to make it right). So far could not find solution.
Thanks in advance
You need to declare the text
property with the @objc
attribute to make it accessible via dynamic dispatch like Key-Value Coding.
Also, because you want modifications of the property to be observable via Key-Value Observing (for Bindings), you need to tell Swift to always dispatch modifications of it dynamically. So, you need to use the dynamic
modifier on the declaration, too:
@objc dynamic var text = NSAttributedString()
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