Currently, If I want to search whether an object is in a NSArray(not sorted) or not. I have to loop over the array and check each object until I found one that match my expectation.
I doubt it’s performance even if the check is only a if statement.
To improve the search performance is there any provided solution?
Or I can only sort the array some way and use some way like binary-search?
Sorting then searching will take more time than a loop iterating over each element of the array since comparison based sorting takes at best O(n * log(n)) time, iterating over the array will take O(n) time for n elements in the array.
A pragmatical solution would be to use NSArray#containsObject if you already know the object.
Otherwise you have to implement your own comparison strategy and step through the array