Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSNumber的NSPredicate包含NSNumber(作为NSString)_Ios_Search Engine_Nspredicate - Fatal编程技术网

Ios NSNumber的NSPredicate包含NSNumber(作为NSString)

Ios NSNumber的NSPredicate包含NSNumber(作为NSString),ios,search-engine,nspredicate,Ios,Search Engine,Nspredicate,简单的方法:我有一个搜索视图,用户可以在其中选择一些CoreDate,他可以搜索名称,城市(都是NSString)和Clientnumber(NSNumber) 这是名称和城市的谓词,但如何在NSNumber字段中搜索searchquery 因此,如果我搜索300,它应该返回带有Clientnumber:300123和1230012的条目,因为这两个都包含300 那么,我该怎么做呢?是否可以将NSPredicate中Clientnumber的值“转换”为NSString?您应该能够使用CAST(

简单的方法:我有一个
搜索视图
,用户可以在其中选择一些CoreDate,他可以搜索
名称
城市
(都是
NSString
)和
Clientnumber
NSNumber

这是名称和城市的谓词,但如何在
NSNumber
字段中搜索searchquery

因此,如果我搜索300,它应该返回带有
Clientnumber
:300123和1230012的条目,因为这两个都包含300


那么,我该怎么做呢?是否可以将
NSPredicate
Clientnumber
的值“转换”为
NSString

您应该能够使用
CAST(Clientnumber,'NSString')contains[cd]@
执行此搜索:

NSPredicate *resultPredicate = [NSPredicate
                            predicateWithFormat:@"Name contains[cd] %@ OR City contains[cd] %@ OR CAST(Clientnumber, 'NSString') contains[cd] %@",
                            searchText,searchText,searchText];

我发现dasblineklight的答案在使用
NSFetchedResultsController的核心数据搜索中不适用。但是,有效的方法是将
number.description
作为属性的名称传递,因此对于这种特定情况:

NSPredicate *resultPredicate = [NSPredicate
                                predicateWithFormat:@"Name contains[cd] %@ OR City contains[cd] %@ OR Clientnumber.description contains[cd] %@",
                                searchText, searchText, searchText];

哦,我不知道这个:D@dasblinkenlight你能提供你阅读这个方法的来源吗?我想多了解一些。谢谢。很遗憾王国不支持CAST方法
NSPredicate *resultPredicate = [NSPredicate
                                predicateWithFormat:@"Name contains[cd] %@ OR City contains[cd] %@ OR Clientnumber.description contains[cd] %@",
                                searchText, searchText, searchText];