Sorting, then the search will take longer than a loop repeating for each element of the array, since sorting based on comparison takes O (n * log (n)) at best, iterating over the array will take O (n) time for n elements in an array.
A pragmatic solution would be to use NSArray # containsObject if you already know the object.
Otherwise, you must implement your own comparison strategy and go through the array
source share