You should not use stringWithFormat
to build a predicate. This will fail if the search strings (playlistID, songQuery) contains special characters, in particular if they contain a quote "
.
A much better and safer method is
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY playlists.playlist_id =[cd] %@ AND name BEGINSWITH[c] %@", playlistID, songQuery];
[request setPredicate:predicate];
because predicateWithFormat
handles all these cases correctly.
(It is mainly the same reason why one should use "prepared statements" for SQL queries, even if this: http://xkcd.com/327/ would probably not happen with Core Data :-)