Created
January 29, 2013 15:37
-
-
Save wess/4665164 to your computer and use it in GitHub Desktop.
A little function to create an HTTP query from an NSPredicate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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