• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSPersistentDocument loading into NSManagedObjectContext
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPersistentDocument loading into NSManagedObjectContext


  • Subject: NSPersistentDocument loading into NSManagedObjectContext
  • From: "Andrew Beck" <email@hidden>
  • Date: Sat, 23 Feb 2008 13:08:36 -0500

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/ - -
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: NSButton Subclass - 2 states plus tracking image
  • Next by Date: Re: Unobserved Changes
  • Previous by thread: Asyncronously copying multiple files.
  • Next by thread: bind tableview to arraycontroller
  • Index(es):
    • Date
    • Thread