Reputation: 557
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 ?
Upvotes: 1
Views: 188
Reputation: 2035
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.
Upvotes: 2