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: "Ernest Schaal" <email@hidden>
- Date: Wed, 11 Jul 2007 13:16:26 +0900
Thank you for your response. I tried it, and it ran, but it gave me a
"Can't modify a named fetch request in an immutable model." error
during the run. Any idea what I am doing wrong?
// Fetch count of Events due within Warning Time Period
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
alertCount = [eventsDue count];
On 7/11/07, Marcus S. Zarra <email@hidden> wrote:
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
_______________________________________________
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