部分匹配获取

时间:2013-06-30 00:40:19

标签: magicalrecord

我希望像partial match中的LIKE一样执行SQL

在Magical Record中,要查找指定字段的值,我们使用findByAttribute

NSArray *productsFoundByTitle = [Product MR_findByAttribute:@"product_title" withValue:@"bags"];

问题是这只会在exact matches中返回bags product_title。我还要返回partial matches,因此也会返回类似mail bags的值。

我怎样才能在MagicalRecord中做到这一点?

2 个答案:

答案 0 :(得分:0)

我到目前为止提供的最佳解决方案如下:绘制所有数据图表,找到Partial matches函数的所有rangeOfString

        NSArray *allResults = [Product MR_findAll];
        for (id element in allResults) {
            if ([[element valueForKey:@"product_title"] rangeOfString:@"bags" options:NSCaseInsensitiveSearch].location != NSNotFound) {

           //I got a partial match, save this instance for later use
          }         
}

答案 1 :(得分:0)

我建议你阅读有关谓词的内容。你正在寻找关键词,如startswith,endswith等。查看predicate programming guide

相关问题