我正在使用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];
}
这是商店实体:
我需要将 name 转换为小写,并查看它是否以小写格式包含在 shopSearchBar.text
中。
例如:
我有这四家商店:
- Shop1
- shop 1
- my shop
- Shop
如果用户搜索文本为“shop”,则必须返回所有这些商店。
你知道如何做吗?
text
是否为 _nil_。只需写if (shopSearchbar.text.length)
,它会在text
为空或为 nil 的情况下返回 _nil_。 - Artem M