Reputation: 435
I Wrote an application that uses core data and it was working fine, on both simulator and devices. Then I made a new git branch of the project and it works perfectly on the simulator but not on the devices.
Here is the code for the fetchedResultsController
-(NSFetchedResultsController *)fetchedResultsController{
if (_fetchedResultsController != nil) {
NSLog(@"Fetched Controler : %@", _fetchedResultsController);
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Membership" inManagedObjectContext:managedObjectContext];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userdata.email == %@", [[NSUserDefaults standardUserDefaults] stringForKey:@"email"]];
NSSortDescriptor *sort1 = [[NSSortDescriptor alloc]initWithKey:@"type" ascending:NO];
NSSortDescriptor *sort2 = [[NSSortDescriptor alloc]initWithKey:@"membership_name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:sort1,sort2, nil];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
[fetchRequest setSortDescriptors:sortDescriptors];
_fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"type" cacheName:nil];
return _fetchedResultsController;
}
Then I fetch the objects in view will apear.
-(void)viewWillAppear:(BOOL)animated{
NSError *error;
[[self fetchedResultsController]performFetch:&error];
[self.tableView reloadData];
}
The managed object context
is passed from appDelegate
to the login view then from the loginView to the second view. On the second view is where I am having problems
The only thing that I can think of is that something is happening with the memory limitations on the device or maybe a concurrency issue?
If there are are any threads created I did not mean to do it.
Upvotes: 0
Views: 253
Reputation: 80265
It seems that your predicate
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"userdata.email == %@",
[[NSUserDefaults standardUserDefaults] stringForKey:@"email"]];
is returning an empty set. Log the value of this user default and I am convinced this will be cleared up.
Upvotes: 1