Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

case insensitivity in NSArray containsObject:

I'm working on an app that checks an array to see if it contains a certain string. However, it doesn't seem to be working right, because I think it may be looking at the case of the string. In this line of code, how would I make sure that containsObject: is being case insensitive?

if ([myArray containsObject:term]) {...}

Please ask if you need clarification, and thanks for your help.

(Also, I've found this question: Case insensitive comparison NSString. I don't know if this is what I need, and if it is, how would I use it)

like image 785
thekmc Avatar asked Nov 15 '11 22:11

thekmc


1 Answers

if ([myArray indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
         return (BOOL)([obj caseInsensitiveCompare:term] == NSOrderedSame);
     }] != NSNotFound) {
    // there's at least one object that matches term case-insensitively
}
like image 85
Lily Ballard Avatar answered Sep 19 '22 22:09

Lily Ballard