NSPredicate核心数据 [英] NSPredicate Core Data

查看:118
本文介绍了NSPredicate核心数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

核心中的 LIKE [c]%@ = [c]%@ 之间有何区别data NSPredicate ?我想搜索一个应该完全匹配接收器的字符串。
例如:

What is the exact difference between LIKE [c]%@ and = [c]%@ in core data NSPredicate? I want to search for a string that should exactly match the receiver. Example :

NSArray *arrayNames = [context fetchObjectsForEntityName:NSStringFromClass([PatientFamilyMember class])
      withSortColumn:nil withSortDescending:FALSE
      withPredicate:@"patientID = %@ && firstName=[c]%@ && relationship=[c]%@ && lastName=[c]%@",
      self.pfm.patientID, firstName, relationship, lastName];

这可行,但我还不明白使用 LIKE [c] = [c]%@。

This works but I have not understood the difference between using LIKE [c] and = [c]%@.

推荐答案

在一个谓词中 LIKE = 之间的区别是 LIKE 允许 * 作为通配符,其中匹配1个字符, * 匹配0个或多个字符。

The difference between LIKE and = in a predicate is that LIKE allows ? and * as wildcard characters, where ? matches 1 character and * matches 0 or more characters.

两者 LIKE可以使用 [c] 修改和 = 以指定不区分大小写。

Both LIKE and = can be modified with [c] to specify case insensitivity.

示例:假设您有对象名称

Example: Assume that you have objects with names

"Mark", "mark", "Mike", "mike", "M*"

b
$ b

Both

[NSPredicate predicateWithFormat:@"name = %@", @"Mark"];
[NSPredicate predicateWithFormat:@"name LIKE %@", @"Mark"];

找到Mark,以及

[NSPredicate predicateWithFormat:@"name =[c] %@", @"Mark"];
[NSPredicate predicateWithFormat:@"name LIKE[c] %@", @"Mark"];

找到Mark和mark。但只有 LIKE 运算符可以与通配符一起使用,例如

find "Mark" and "mark". But only the LIKE operator can be used with wildcards, e.g.

[NSPredicate predicateWithFormat:@"name LIKE[c] %@", @"M*"];

找到Mark,mark,Mike,mike ,但

finds "Mark", "mark", "Mike", "mike" and "M*", but

[NSPredicate predicateWithFormat:@"name ==[c] %@", @"M*"];

只找到M *。

查看有关详细信息,请参见谓词编程指南中的字符串比较。

See String Comparisons in the "Predicate Programming Guide" for more information.

这篇关于NSPredicate核心数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆