ios - iOS中使用谓词的小写模型对象

标签 ios objective-c core-data nspredicate

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"eventName In[c] %@", eventNameArray];
在此代码中,我希望eventName键为小写字母以进行匹配,上面的代码为我提供了eventNameArray对象为小写字母。
eventName是我的核心数据模型中的对象之一,我希望将其小写。
NSArray *dbArray = [[NSArray alloc] initWithObjects:@"Add To Cart",@"Add To Cart",@"Lead Submitted",@"Add To Cart",@"Product Purchase", nil];
NSArray *eventArray = [[NSArray alloc] initWithObjects:@"add to cart",@"lead submitted", nil];
    
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self IN[c] %@", eventArray];
    
NSLog(@"%@",[dbArray filteredArrayUsingPredicate:predicate]);
这很好用,但不适用于模型对象。

最佳答案

您可以使用lowercase:()函数将属性强制转换为小写字母:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"lowercase:(eventName) IN[c] %@", eventNameArray];

关于ios - iOS中使用谓词的小写模型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62909043/

相关文章:

ios - 邀请的 TestFlight 问题

ios - 如何编辑由 Firebase 动态链接自动生成的 apple-app-site-association 文件?

ios - App更新后如何唤醒?

objective-c - 从距当前位置最近到最远对 NSManagedObject 进行排序

ios - RestKit - 一次处理一个 REST 操作

ios - SDWebImage无法从NSDictionary加载图像

ios - 使用 Monotouch 在 iPhone 上重用音频和录音

ios - 如何同时覆盖 initWithFrame : and initWithCoder: in subclass of UIView?

objective-c - 变量参数列表中的非 POD 类型

ios - Swift 4 - 无法仅在物理设备上将类型 'NSDate' 的值分配给类型 'Date?'