Re: Using an ExecuteFetchRequest in a Core Data Document-based Application
Re: Using an ExecuteFetchRequest in a Core Data Document-based Application
- Subject: Re: Using an ExecuteFetchRequest in a Core Data Document-based Application
- From: "Marcus S. Zarra" <email@hidden>
- Date: Tue, 10 Jul 2007 21:43:40 -0600
You need to execute the fetchRequest against the context and not the
model. Therefore your code should be something like this:
NSManagedObjectContext *context = [self managedObjectContext]; //MSZ:
Or wherever your context is located
NSManagedObjectModel *model = [self managedObjectModel];
NSFetchRequest *fetch = [model fetchRequestTemplateForName:@"warning"];
NSLog (@"Fetch: %@", [fetch description]); //MSZ: Always use a
formatted string in logs
// Used to see if the fetch request was okay in format
NSError *error = nil;
NSArray *eventsDue = [context executeFetchRequest:fetch error:&error];
NSAssert(eventsDue != nil, ([NSString stringWithFormat:@"Fetch
Failed: %@", error])); //MSZ: test for failure
Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com
On Jul 10, 2007, at 9:34 PM, Ernest Schaal wrote:
I have been having trouble the past couple of days finding how to use
a fetch request in core data model. I figured out how to enter the
fetch request into the model, and I got to the point where I defined a
fetch request, but the line with the executeFetchRequest is the
problem.
Here is the pertinent code:
NSManagedObjectModel *model = [self managedObjectModel];
NSFetchRequest *fetch = [model
fetchRequestTemplateForName:@"warning"];
NSLog ([fetch description]);
// Used to see if the fetch request was okay in format
NSError *error = nil;
NSArray *eventsDue = [model executeFetchRequest:fetch error:&error];
...
I know that "model" is not the right term, nether are
"ManagedObjectContext" or "Context". I just don't know what the right
term is.
I have googled "executeFetchRequest model" and found very little on
it.
Please tell me what I should be doing.
_______________________________________________
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:
40zarrastudios.com
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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