views:

18

answers:

1
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 ?

+1  A: 

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.

lyonanderson