0
votes

This code causes a crash with error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.

self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSLog(@"point one");
NSString *yourTrip=@"trip1";
NSFetchRequest *request = [[NSFetchRequest alloc] init];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"thetrip== %@", yourTrip];

[request setEntity:[NSEntityDescription entityForName:@"thetrip" inManagedObjectContext:managedObjectContext]];

[request setPredicate:predicate];

NSError *error = nil;

NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
if (array == nil)
{
    NSLog(@"problemo");
}

The crash specifically happens after the NSError *error =nil;

1
And, do you have an entity called thetrip? Log the entity description.Wain

1 Answers

0
votes

I would change your

NSLog(@"problemo");

for a

NSLog(@"problemo %@", [error localizedDescription]);

in order to have more information about what the error was.

I think (as well as @Wain) that you might not have an entity called 'thetrip' (maybe theTrip? be aware that Core Data is case sensitive). The log with the localized description will give you some hints about your problem.