parse.com - Parse NSPredicate with nil option for finding any object -
i have tried search web, , didn't came across subject regarding default fallbacks nspredicate driven queries.
for instance want query jokes category.
so got little helper method:
- (pfquery)queryjokeswithcategory:(pfobject *)category language:(nsstring *)language { nspredicate *predicate = [nspredicate predicatewithformat:@"language = %@ , category = %@", language, category]; pfquery *jokes = [pfquery querywithclassname:@"joke" predicate:predicate]; return jokes; } if pass nil category expect jokes, doesn't give me single. this:
pfquery *jokesquery = [self queryforjokeswithcategory:nil language:@"en"]; are there ways approach? keywords specific have missed?
what want in situation check if "category" key exists, , in case, will, run query:
nspredicate *predicate = [nspredicate predicatewithformat:@"language = %@ , category in self", language]; pfquery *jokes = [pfquery querywithclassname:@"joke" predicate:predicate]; return jokes; this query query joke table jokes specified language, disregarding category, ensuring defined.
edit:
i don't know how app works, sounds user needs enter category , language, , want construct query based on entry. have check see if field category empty, , query posted above, , if wasn't empty, use original query. don't think can accomplish in 1 query, though.
as suggestion, maybe make category field mandatory, or have "view all" button view jokes under selected language.
Comments
Post a Comment