【问题标题】:Lowercase model object in iOS using predicateiOS中使用谓词的小写模型对象
【发布时间】:2020-07-15 06:47:43
【问题描述】:
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]);

这工作正常,但不适用于模型对象。

【问题讨论】:

    标签: ios objective-c core-data nspredicate


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢,为此苦苦挣扎了几天,尝试了不同的组合。不知道这个。
    猜你喜欢
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多