简单方法:我有一个SearchView,用户可以选择一些CoreDate,他可以搜索Name、City (都是NSString)和Clientnumber (NSNumber)
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"Name contains[cd] %@ OR City contains[cd] %@",
searchText,searchText];这是我对Name和City的谓词,但是如何在NSNumber字段中搜索搜索查询呢?
因此,如果我要搜索300个,它应该返回带有Clientnumber:300123和1230012的条目,因为两个都包含 300 。
那我该怎么做呢?是否可以将Clientnumber在NSPredicate中的值“转换”为NSString
发布于 2014-06-16 13:00:04
您应该能够使用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];发布于 2017-07-13 07:50:16
我发现,在使用NSFetchedResultsController进行核心数据搜索时,dasblineklight的答案对我来说是行不通的。然而,真正起作用的是将number.description作为属性的名称传递,因此对于这种特殊情况,如下所示:
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"Name contains[cd] %@ OR City contains[cd] %@ OR Clientnumber.description contains[cd] %@",
searchText, searchText, searchText];https://stackoverflow.com/questions/24244268
复制相似问题