Skip navigation.
 
mlNSPersistentDocument loading into NSManagedObjectContext
FROM : Andrew Beck
DATE : Sat Feb 23 19:08:36 2008

Hi,

During init time (awakeFromNib), I build a list of objects into a mutable
dictionary, keyed by an [NSManagedObject objectID].
I load the objects up, then check to see if there are any NSManagedObjects
in the managedObjectContext with the same name as the objects I load during
init time. If they aren't there, I create a new NSManagedObject. Then I put
my object in the dictionary, keyed by the NSManagedObject I either found or
created.

This procedure works fine for new documents.

But when I am loading from a file, I can't find any init-time method that
can access the fully loaded managedObjectContext.
I have overrided many methods trying to find where the NSPersistentDocument
is fully loaded, the one that is documented for NSDocument is called
"initWithContentsOfURL"

- (id)initWithContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
error:(NSError **)outError
{
    self = [super initWithContentsOfURL:absoluteURL ofType:typeName
error:outError];

    NSLog(@"the context is size %d during initWithContentsOfURL", [[[self
managedObjectContext] registeredObjects] count]);

    return self;
}

this returns a context of size 0, other methods I have tried include
awakefromnib, configurePersistentStoreCoordinatorForURL,
windowControllerDidLoadNib, etc. All return 0 for [[[self
managedObjectContext] registeredObjects] count].

I have referred the mailing list archive message:
http://lists.apple.com/archives/cocoa-dev/2005/Oct/msg00993.html

but this doesn't solve the problem.

Also - I am using 10.4 (I think the only difference here is the new
configurePersistentStoreCoordinatorForURL method)

Thanks in advance
--
/andrew
  - - http://www.andrewbeckmusic.com/ - -

Related mailsAuthorDate
No related mails found.