Re: Loading Entities from a CoreData document
Re: Loading Entities from a CoreData document
- Subject: Re: Loading Entities from a CoreData document
- From: Jerry Krinock <email@hidden>
- Date: Thu, 16 Apr 2009 22:55:24 -0700
On 2009 Apr 16, at 22:04, David Zwerdling wrote:
The issue is, when using code like this (url points to a document
full of data sets):
NSPersistentDocument *pd = [NSPersistentDocument new];
BOOL success = [pd configurePersistentStoreCoordinatorForURL:url
ofType:NSXMLStoreType modelConfiguration:nil storeOptions:nil
error:&error];
NSSet *ros = [[pd managedObjectContext] registeredObjects];
success comes back true, but there are no managed objects in 'ros'.
I've never used -registeredObjects. You might want to try my little -
allObjects method given below and see if you get the same empty results.
So, is there some sample code I can see which loads the managed
objects of an xml file? I've looked pretty exhaustively and
everything seems too high level (relying on the single-file model
that I implemented in my original application.)
Well, I don't think your situation is any different than what's in the
sample code available. For example, DepartmentAndEmployees has a
method which fetches the 'Department'.
Actually, and I want to go to bed now, but just quickly looking at
your code above it looks like there might be some things missing.
Creating a persistence stack usually takes me a few more lines than
that. Don't you need to plug in a managed object model somewhere?
- (NSArray*)allObjects {
NSError* error_ = nil ;
NSFetchRequest* fetchRequest ;
fetchRequest = [[NSFetchRequest alloc] init];
NSManagedObjectContext* moc = <<whatever>> ;
[fetchRequest setEntity:[NSEntityDescription
entityForName:<<whatever>>
inManagedObjectContext:moc]];
NSArray* allObjects = [moc executeFetchRequest:fetchRequest
error:&error_] ;
if (error_) {
[[self errorHandler] setError:error_] ;
NSLog(@"Error executing fetch request: %@", [error_
localizedDescription]) ;
}
[fetchRequest release] ;
return allObjects ;
}
_______________________________________________
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