Akii_iOS Akii_iOS - 9 months ago 52
iOS Question

how to work with NSPredicate

I am try to search word which contain "EVBAR02". Can any body help me in this case. Here is Array Directory.

Here is code.

`NSMutableArray *filteredListContent = [NSMutableArray arrayWithArray:arrayGallery];
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"imageUrl CONTAINS[cd] EVBAR02"];
[filteredListContent filterUsingPredicate:predicate];`

arrayGallery = (
imageId = "04";
imageUrl = "/article/THEV-EVBAR04.jpg";
imageId = "02";
imageUrl = "/article/THEV-EVBAR02.jpg";
imageId = "06";
imageUrl = "/article/THEV-EVBAR06.jpg";

But Its not working. What to do?


The ...WithFormat part of predicateWithFormat: works the same way like stringWithFormat:

NSString *searchString = @"EVBAR02";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"imageUrl CONTAINS[cd] %@", searchString];

Or literally in single quotes:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"imageUrl CONTAINS[cd] 'EVBAR02'"];

The quotation is required as described in the documentation:

String constants must be quoted within the expression—single and double quotes are both acceptable, but must be paired appropriately (that is, a double quote (") does not match a single quote ('))