NSPredicate comparing transformed CLPlacemark with another CLPlacemark

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

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] 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!