Skip to content

Instantly share code, notes, and snippets.

@wess
Created January 29, 2013 15:37
Show Gist options
  • Save wess/4665164 to your computer and use it in GitHub Desktop.
Save wess/4665164 to your computer and use it in GitHub Desktop.
A little function to create an HTTP query from an NSPredicate
NSMutableDictionary *generateQueryPartForPredicate(NSPredicate *predicate)
{
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
if([predicate isKindOfClass:[NSCompoundPredicate class]])
{
NSCompoundPredicate *compoundPredicate = (NSCompoundPredicate *)predicate;
for(NSComparisonPredicate *comparison in compoundPredicate.subpredicates)
[params setValue:comparison.rightExpression.constantValue forKey:comparison.leftExpression.keyPath];
return params;
}
else if([predicate isKindOfClass:[NSComparisonPredicate class]])
{
NSComparisonPredicate *comparePredicate = (NSComparisonPredicate *)predicate;
[params setValue:comparePredicate.rightExpression.constantValue forKey:comparePredicate.leftExpression.keyPath];
return params;
}
return [NSMutableDictionary new];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment