NSPersistentDocument is not designed to work with “modern” features like 
private queue MOCs. So I expect you are going to be playing whack-a-mole if you 
go this route. I just switched to Mike Abdullah’s BSManagedDocument. It is like 
UIManagedDocument, but for OS X. If you don’t have any customers on this app 
yet, BSManagedDocument is pretty much a drop-in replacement for 
NSPersistentDocument. If you have customers, you will need to migrate them, but 
that is straightforward and probably much lower risk than trying to get 
NSPersistentDocument to support something it is not designed for.

> On Feb 3, 2015, at 1:48 AM, Steve Mills <sjmi...@mac.com> wrote:
> 
> On Feb 2, 2015, at 17:36:22, Roland King <r...@rols.org> wrote:
>> 
>> get the NSManagedObjectContext the document creates for you with [ super 
>> managedObjectContext ], get the store coordinator with [ 
>> managedObjectContext persistentStoreCoordinator ], create your own MOCs on 
>> that store, hold on to the MOC you have just created, ignore the one super 
>> created (or perhaps you can nil it, not sure) and then return it. 
> 
> That sounds interesting. I've tried it, and it causes my managedObjectContext 
> override to be called twice during document creation. The 2nd call is caused 
> by my managedObjectContext override calling [super managedObjectContext], and 
> super tries to set up the undo manager for its managedObjectContext. I don't 
> know if this is harmless or OK.
> 
> So since no exceptions are thrown during the creating of my own MOCs, I go 
> ahead and add objects to a temp private MOC whose parent is my 
> managedObjectContext. That works and my table view is populated after it 
> completes. But when I try to save at the end of my concurrent object-adding 
> block, it throws:
> 
> CoreData: error: Illegal attempt to save to a file that was never opened. 
> "This NSPersistentStoreCoordinator has no persistent stores (unknown).  It 
> cannot perform a save operation.". No last error recorded.
> An uncaught exception was raised
> This NSPersistentStoreCoordinator has no persistent stores (unknown).  It 
> cannot perform a save operation.
> (
>       0   CoreFoundation                      0x00007fff8569b66c 
> __exceptionPreprocess + 172
>       1   libobjc.A.dylib                     0x00007fff87dfd76e 
> objc_exception_throw + 43
>       2   CoreData                            0x00007fff898b7eb3 
> -[NSPersistentStoreCoordinator 
> _coordinator_you_never_successfully_opened_the_database_so_saving_back_to_it_is_kinda_hard:]
>  + 51
>       3   CoreData                            0x00007fff898b810d 
> -[NSPersistentStoreCoordinator _introspectLastErrorAndThrow] + 77
>       4   CoreData                            0x00007fff898b8236 
> __65-[NSPersistentStoreCoordinator 
> executeRequest:withContext:error:]_block_invoke + 166
>       5   CoreData                            0x00007fff898c331b 
> gutsOfBlockToNSPersistentStoreCoordinatorPerform + 171
>       6   libdispatch.dylib                   0x0000000100025d43 
> _dispatch_client_callout + 8
>       7   libdispatch.dylib                   0x00000001000270b1 
> _dispatch_barrier_sync_f_invoke + 348
>       8   CoreData                            0x00007fff898b2312 _perform + 
> 194
>       9   CoreData                            0x00007fff89804395 
> -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 533
>       10  CoreData                            0x00007fff898043c4 
> -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 580
>       11  CoreData                            0x00007fff8982eb3b 
> -[NSManagedObjectContext save:] + 1291
>       12  Image Chest                         0x0000000100002291 -[Document 
> unsafeSaveContext:] + 113
>       13  Image Chest                         0x000000010000213a 
> __24-[Document saveContext:]_block_invoke + 42
>       14  CoreData                            0x00007fff8984a246 
> developerSubmittedBlockToNSManagedObjectContextPerform + 182
>       15  libdispatch.dylib                   0x0000000100025d43 
> _dispatch_client_callout + 8
>       16  libdispatch.dylib                   0x0000000100029fb3 
> _dispatch_queue_drain + 1804
>       17  libdispatch.dylib                   0x000000010002bfc0 
> _dispatch_queue_invoke + 223
>       18  libdispatch.dylib                   0x0000000100028f5e 
> _dispatch_root_queue_drain + 666
>       19  libdispatch.dylib                   0x000000010003acd0 
> _dispatch_worker_thread3 + 106
>       20  libsystem_pthread.dylib             0x00007fff92a82637 
> _pthread_wqthread + 729
>       21  libsystem_pthread.dylib             0x00007fff92a8040d 
> start_wqthread + 13
> )
> 
> The save model is based on Jerry's YaBT sample mentioned earlier in the 
> thread, which has a rootContext (NSPrivateQueueConcurrencyType), mainContext 
> (NSMainQueueConcurrencyType), and tempContext (NSPrivateQueueConcurrencyType) 
> in a chain of children. I'm guessing it's because the document has not been 
> saved to disk yet, whereas the YaBT sets up a file for the persistent store 
> when it creates it. Since the document sets up the store, I don't know what 
> I'd do in this case.
> 
> Ugh. This needs to be more complicated and harder to comprehend.
> 
> --
> Steve Mills
> Drummer, Mac geek
> 
> 
> _______________________________________________
> 
> 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/dave.fernandes%40utoronto.ca
> 
> This email sent to dave.fernan...@utoronto.ca


_______________________________________________

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