问题
I'm saving CLPlacemark in Core data using NSValueTransformer. (so it's saved as NSData)
However I've come to a point where I need to filter the saved objects based on another CLPlacemark object.
I've tried this, it doesn't work:
NSExpression *exprPath = [NSExpression expressionForKeyPath:@"placemark"];
NSExpression *exprKeyword = [NSExpression expressionForConstantValue:[NSKeyedArchiver archivedDataWithRootObject:placemark]];
NSPredicate *predicate = [NSComparisonPredicate predicateWithLeftExpression:exprPath rightExpression:exprKeyword modifier:NSDirectPredicateModifier type:NSEqualToPredicateOperatorType options:0];
So any other suggestions?
回答1:
Core Data supports == and != searches against binary data (and transformable attributes). Do not use NSKeyedArchiver for your placemark. Just use it as is in predicate like this:
[NSPredicate predicateWithFormat:@"placemark = %@", placemark]
来源:https://stackoverflow.com/questions/15204498/nspredicate-comparing-transformed-clplacemark-with-another-clplacemark