Im building an app where users will be able to filter through a set of photos based on 4 parameters:
model http://seismicdevelopment.com/shot.png
FeedType and PhotoType can be one of three possible values respectively. Market and Tag can contain multiple values that describe the photo. I have the ui setup where for FeedType/PhotoType is a series of UISwitches for each param. If you turn one value on, the others in that group will turn off.
Market/Tag have UIButtons that can be made selected/normal. Any selected button should be added to the filtering to narrow results.
I can’t seem to figure out how I should write the filtering logic to be most effective. Essentially on any control change, I need to rewrite the predicate filter but I can’t seem to wrap my head around how I can link the separate param filters together.
For Tag/Market I’d also like to add a disabled state for UIButtons that have no records, or no records based on the currently selected buttons.
It is hard to tell a precise advice without knowing what kind the parameters are, but, as far as i can see, you need to have four variables,more likely,NSStrings, and every time the user changes the parameter, you create a new fetch predicate, by appending all that variables with the right format. That’s how i see it in general.
UPDATE
So, with Market and Tag Butons everything is quite obvious – you shoud use
NSCompondPredicate. You’ll need an array of predicates, so make a property.Then, each time user touches the button, you add or remove that narrowing predicate.
Same thing for
MarketsYou should also add two variables,i guess,
NSPredicatesorNSString,that will hold the value of selectedFeedTypeandPhotoType,lets’s call themfeedTypePredicateandphotoTypePredicaterespectivly. When user touches those switches(why not segmentedControls?), you just change their’s values.And, finally, you should just combine all those predicates into one and make your fetch!