I have the simplest of Document-based macOS apps created in Xcode 8.2.3. In the 
Document.makeWindowControllers method, I set my ViewController's 
representedObject to the document.

override func makeWindowControllers() {
    let storyboard = NSStoryboard(name: "Main", bundle: nil)
    let windowController = storyboard.instantiateController(withIdentifier: 
"Document Window Controller") as! NSWindowController
    
    let vc = windowController.contentViewController as! ViewController
    vc.representedObject = self
    
    self.addWindowController(windowController)
}


In the Storyboard, I bind an Array Controller in the View Controller scene to 
ViewController.self.representedObject.managedObjectContext.

I don't have anything bound to the Array Controller (yet). But after launching 
and displaying the window, I get this (note the first message is me making sure 
my representedObject is getting set):

ViewController.swift:25    Set represented object to: 
Optional(<PromotionalChargeManager.Document: 0x600000120960>)
2017-02-08 15:39:41.178728 PromotionalChargeManager[51621:17330300] [General] 
Cannot perform operation without a managed object context
2017-02-08 15:39:41.181165 PromotionalChargeManager[51621:17330300] [General] (
        0   CoreFoundation                      0x00007fffc9edd0db 
__exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x00007fffdeb6ea2a 
objc_exception_throw + 48
        2   CoreFoundation                      0x00007fffc9f5a9c5 
+[NSException raise:format:] + 197
        3   AppKit                              0x00007fffc80281bc 
-[_NSManagedProxy _managedObjectContext] + 66
        4   AppKit                              0x00007fffc80281dc 
-[_NSManagedProxy _persistentStoreCoordinator] + 22
        5   AppKit                              0x00007fffc802824f 
-[_NSManagedProxy _entity] + 46
...

Now, as far as I can tell, I'm doing EXACTLY what Apple says I should do in

        https://developer.apple.com/library/content/qa/qa1871/_index.html

Note that I've also tried setting the Array Controller's content binding to 
gobbledegook, hoping for a complaint about something not being KVO-compliant 
for that nonexistent property. No such luck.

What am I doing wrong?

Thanks!

-- 
Rick Mann
rm...@latencyzero.com



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to