Fernandes
Fernandes

Reputation: 216

Array filtered with another array (CS and Predicate)

The following code print the line below:


TestApp[1156:207] Array: (
    "Type A"
)

But isn't right. The NSPredicate should ignore the case sensitive.
Does anyone know what I'm doing wrong?

    NSArray *array = [[NSArray alloc] initWithObjects:[[TestObject alloc] initWithType:@"Type A"],
                                                      [[TestObject alloc] initWithType:@"Type B"],
                                                      [[TestObject alloc] initWithType:@"Type C"],
                                                      [[TestObject alloc] initWithType:@"Type D"],
                                                      [[TestObject alloc] initWithType:@"Type E"], nil];

    NSArray *filter = [[NSArray alloc] initWithObjects:@"Type A", @"Type d", nil];

    NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF.type IN[cd] %@", filter];

    NSLog(@"Array: %@", [array filteredArrayUsingPredicate:predicate]);

Upvotes: 2

Views: 593

Answers (1)

coverback
coverback

Reputation: 4413

The similar issue was raised in this thread: Case insensitive NSPredicate for strings from an array?

It seems that IN does not support [c] modifier. Solution for your case is to change the query, e.g. to use CONTAINS.

[NSPredicate predicateWithFormat: @"ANY %@ CONTAINS[cd] SELF.type", filter]

Upvotes: 2

Related Questions