NSPredicate *predicate = [NSPredicate predicateWithFormat:@"List.name == 'kristof\\'s list'"];
Works as expected.
However I want do something like this:
NSString *listName = [[[detailItem valueForKey:@"name"] description] stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"List.name == '%@'", listName];
It returns nothing, even if I try this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"List.name == '%@'", @"kristof\\'s list"];
It remains empty.
Any ideas ?
The behaviour of [NSString stringWithFormat] and [NSPredicate predicateWithFormat] are different. NSString performs the substitution on creation, whereas NSPredicate on evaluation. Your single quotes are preventing the substitution.
For more take a look at the CocoaDev Forums.