Reputation: 11
The error I can't resolve is ... valueForUndefinedKey:]: this class is not key value coding-compliant for the key managedObjectContext
Here's the code snippet in question (I think) ...
class TripSplitViewController: NSSplitViewController {
@IBOutlet var tripsArrayController: NSArrayController!
var managedObjectContext = (NSApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
I am using Swift 4 and Xcode 9.4 (macOS app) along with Core Data accessing a SQLite data base. I have also created 3 data models with relationships defined between each. I have also create a Split View Controller and am trying to establish my ManagedObjectContext.
One think I have done is check my binds and outlets connections and all look clean and connected correctly.
I am pretty new to Swift and Xcode and this is the first issue I have encountered that all the post on stack responses have not worked in my application.
And one final thing, app was working fine with Core Data until I added the Array Controller to a Split View Controller, the outlet and its connection and the var declaration for the managedObjectContext.
Please, any help is appreciated.
Upvotes: 1
Views: 194
Reputation: 15623
From Using Key-Value Observing in Swift:
Mark properties that you want to observe through key-value observing with both the @objc attribute and the dynamic modifier.
Cocoa Bindings uses KVO. Change
var managedObjectContext = (NSApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
to
@objc dynamic var managedObjectContext = (NSApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
Upvotes: 2