本文介绍了NSPredicate将变换的CLPlacemark与另一个CLPlacemark进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSValueTransformer 在Core数据中保存 CLPlacemark 。 (所以它保存为 NSData

I'm saving CLPlacemark in Core data using NSValueTransformer. (so it's saved as NSData)

但是我来到一个点,我需要过滤保存基于另一个对象 CLPlacemark 对象。

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];

那么任何其他建议吗?

推荐答案

Core Data支持对二进制数据(和可变属性)的==和!=搜索。不要使用 NSKeyedArchiver 作为您的地标。只需像谓语一样使用它:

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]

这篇关于NSPredicate将变换的CLPlacemark与另一个CLPlacemark进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 02:01