Hi
In my RSS Reader App when the application quits or enters the background I count the unread items in the entity that holds the storys with the following:
That is in a class but is called from the app delegate so the passed managed object context is:
That works fine, however I have a FeedInfo entity (holding the name, summary URL of the feed etc) and obviously with a relationship between the two. In the FeedInfo entity I have a 'show' attribute which lets the user decide if they wish for the feed to display in the app.
So, say I have 5 feeds with 20 unread items each, the application badge shows 100 which is correct. However if the user hides two feeds it still shows 100 BUT I want it to show 60.
I have also tried:
But get the following error:
My question is, how can I adapt the above code to take into account the 'show' attribute with the least amount of overhead? Code examples would be good as I'm still trying to learn
My entity diagram is attached.
In my RSS Reader App when the application quits or enters the background I count the unread items in the entity that holds the storys with the following:
PHP:
- (int)countUnreadItems {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"FeedItem" inManagedObjectContext:managedObjectContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@" read = 0"];
[request setPredicate:predicate];
NSError *err;
NSUInteger count = [managedObjectContext countForFetchRequest:request error:&err];
if(count == NSNotFound) {
//Handle error
}
return count;
}
PHP:
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext_ != nil) {
return managedObjectContext_;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}
So, say I have 5 feeds with 20 unread items each, the application badge shows 100 which is correct. However if the user hides two feeds it still shows 100 BUT I want it to show 60.
I have also tried:
PHP:
- (int)countUnreadItems {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setIncludesSubentities:YES];
[request setEntity:[NSEntityDescription entityForName:@"FeedInfo" inManagedObjectContext:managedObjectContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@" (show = 1) AND (read = 0)"];
[request setPredicate:predicate];
NSError *err;
NSUInteger count = [managedObjectContext countForFetchRequest:request error:&err];
if(count == NSNotFound) {
//Handle error
}
return count;
}
But get the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath read not found in entity <NSSQLEntity FeedInfo id=1>'
My question is, how can I adapt the above code to take into account the 'show' attribute with the least amount of overhead? Code examples would be good as I'm still trying to learn
My entity diagram is attached.