I’m working with an app using CoreData. I have a simple structure:
Name
Lastname
I need to update an entry so I do:
if (strLastname.lengt > 0) {
predicate = [NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@ AND dbLastname LIKE[c] %@)", strName, strLastname];
else {
predicate = [NSPredicate predicateWithFormat:@"(dbName LIKE[c] %@)", strName];
}
now the problem is when my DB contains more user with same name and one of them has no lastname, the predicate will match always the first entry where the name is like strName so I should check if dbLastname is like ” but it fails:
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];
}
the predicate is OK but fetchedObject is empty.
Any help is appreciated.
Max
Found a way. I check the length.