Reputation: 7050
I need to append my custom string into NSPredicate
.
So I wrote following codes.
self.query = [[NSMetadataQuery alloc] init];
[self.query setSearchScopes: [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K like '%@*'",NSMetadataItemFSNameKey,whereAreYou];
NSLog(@"%@",pred.description);
[self.query setPredicate:pred];
However when I test it , it only return following value.
kMDItemFSName LIKE "%@*"
the placeholder %@
is not append correctly. It only showing %@
sign.
How can I do that?
Upvotes: 1
Views: 595
Reputation: 539685
Format arguments inside quotation marks are not expanded by predicateWithFormat
,
therefore @"%K like '%@*'"
does not work.
This should work:
NSString *pattern = [NSString stringWithFormat:@"%@*", whereAreYou];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K LIKE %@", NSMetadataItemFSNameKey, pattern];
Upvotes: 4