I am building a self-quiz style app. It is basically a collection view of full-screen slides. Each slide has multiple annotations that the user taps to test themselves. The slides are grouped into categories, the user can filter by category.
I would like to implement the ability to also filter the annotations based on whether the user has marked them known/not known/etc. My current data model (relevant parts) looks like this:
--------------- ---------------------------------------------
| Slide | | Annotation |
--------------- ---------------------------------------------
| name | | lastKnown (enum for known/not known/etc.) |
| category | | ... |
--------------- ---------------------------------------------
| annotations | <--->> | slide |
--------------- ---------------------------------------------
Since the last known/not known/etc. response lives in the annotation object, it seems to me that I need to:
I'm all set on 1 and 2, but having trouble on 3. My understanding at this point is that each slide's annotation relationship will return an NSSet of the annotation objects. It seems I need to test each of these to see if they match the criteria in the known/not known/etc. filter. It also seems to me that I should do it in a predicate, so I can just reload the collection view to refresh the data.
Can anyone offer some best practices on the most efficient way to approach 3?
You should look into the ANY operation:
NSPredicate *slidePredicate = [NSPredicate predicateWithFormat:@"category == 'category'"];
NSPredicate *annotationPredicate = [NSPredicate predicateWithFormat:@"ANY annotations.lastKnown = 'known'"];
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[slidePredicate, annotationPredicate]];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments