nspredicate with coredata fetchrequest
问题描述:
我正在使用使用CoreData的应用程序。我有一个简单的结构:nspredicate with coredata fetchrequest
名称 姓
我需要更新的项目,所以我做的:
if (strLastname.lengt > 0) {
predicate = [NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@ AND dbLastname LIKE[c] %@)", strName, strLastname];
else {
predicate = [NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@)", strName];
}
现在的问题是,当我的数据库包含具有相同的名称和一个多用户他们没有名字,谓词总是匹配第一个条目,其中名称就像则strName所以我应该检查是否dbLastname就像“”,但它失败:
if (strLastname.lengt > 0) {
predicate = [NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@ AND dbLastname LIKE[c] %@)", strName, strLastname];
else {
predicate = [NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@ AND dbLastname LIKE[c] '')", strName];
}
谓词可以,但fetchedObject是空的。
任何帮助表示赞赏。
最大
答
找到了一个方法。我检查了长度。
[NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@ AND not dbLastname.length > 0)", strName];
答
代替LIKE试载,这个固定的问题,对我来说,当我碰到了同样的问题。此外,请正确检查所有拼写,无论您在那里粘贴哪些字段名称和变量,谓词都是正确的。
我试过像,不喜欢,包含,不包含,他们都没有工作。 – masgar
找到了一个方法。我看到了这个长度。 [NSPredicate predicateWithFormat:@“(dbName LIKE [c]%@ AND not dbLastname.length> 0)”,strName]; – masgar