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/