Van*_*nel 18 core-data nspredicate ios
我正在使用iOS SDK 6.0和XCode 4.5.2开发iOS应用程序.我的目标发展是4.3.
我正在使用Core Data来管理我的数据.现在我有这个NSPredicate搜索商店:
if ((shopSearchBar.text != nil) && ([shopSearchBar.text length] > 0))
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@",shopSearchBar.text];
[fetchRequest setPredicate:predicate];
}
Run Code Online (Sandbox Code Playgroud)
这是Shop实体:

我必须将名称转换为小写,看看它是否包含shopSearchBar.text小写格式.
例:
我有这四家店:
如果用户搜索文本是"shop",则必须返回所有文本.
你知道怎么做吗?
Van*_*nel 62
这就是我解决问题的方法:
if ((shopSearchBar.text != nil) && ([shopSearchBar.text length] > 0))
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@",
shopSearchBar.text];
[fetchRequest setPredicate:predicate];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30901 次 |
| 最近记录: |