NSPumber的NSPredicate包含NSNumber(作为NSString)

lon*_*ngi 2 search-engine nspredicate ios

简单的方法:我有一个SearchView用户可以选择一些CoreDate的地方,他可以搜索Name,City(两者NSString)和Clientnumber(NSNumber)

NSPredicate *resultPredicate = [NSPredicate
                                predicateWithFormat:@"Name contains[cd] %@ OR City contains[cd] %@",
                                searchText,searchText];
Run Code Online (Sandbox Code Playgroud)

这是我对名称和城市的谓词,但是如何在NSNumber字段中搜索搜索查询?

所以,如果我想搜索300,它应该返回的条目Clientnumber:300123和1230012,因为这两个包含了300.

那么,我该怎么做呢?是否有可能"转换"的值Clientnumber之内NSPredicate来NSString?

das*_*ght 6

您应该可以使用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];
Run Code Online (Sandbox Code Playgroud)