Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Blog Reader Course: filter content

Following the exaple of the diary app, I'm making an app which lets the user add subjects and then add assignments from a subject previously added. I'm using two entities: the first one for adding the subject with its teacher and so, and the second one for adding assignments. I have a tableViewController which shows all the subjects and by tapping in one of them, another storyboard scene appears to show the assignments related to that subject and add new ones. The problem I have is that when I add a new assignment, it appears in all subject scenes, because I don't know how to filter the assignments depending on the subject.

I'd be very grateful if someone could help me with this. Thanks!

2 Answers

I'm not sure I fully understand how you're trying to filter the assignments.

You might try making an assignment class that has a subject property. Then when you select and pass around assignments you can access the property to check what subject the assignment is.

Here are some code pieces that might help:

Assignment *hw1 = [[Assignment alloc] init]; hw1.subject = @"math";

if ([hw1.subject isEqual]){ //do something b/c you have a math assignment }

Hi Fred,

I'd already done this but I'm having problems with the NSFetchRequest and the NSPredicate because I'm not able to figure out how to filter the entities by its -subject- property name.

How do you cache the JSON api?