我正在使用使用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是空的。
任何幫助表示讚賞。
最大
我試過像,不喜歡,包含,不包含,他們都沒有工作。 – masgar
找到了一個方法。我看到了這個長度。 [NSPredicate predicateWithFormat:@「(dbName LIKE [c]%@ AND not dbLastname.length> 0)」,strName]; – masgar