So I have 4 text fields in which a user can use to narrow down table results in order to find an exact place. My problem is that since a user does not have to type something in each text field, I can’t simply use AND in my predicate.
Right now I have the opposite from what I’d like my app to do. If one types in a City and a State, my predicate shows more results rather than narrowing the results. Which makes perfect sense to why its doing that.
Other than creating many if statements based on what text fields are empty or not, is there an better way around this?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(place CONTAINS[c] %@) OR (city CONTAINS[c] %@) OR (state CONTAINS[c] %@) OR (zip CONTAINS[c] %@)",
userPlace, userCity, userState, userZip];
I think this is what you want: