I have searched this on the internet, but have found no solution…
Here is what I want:
Say I have an NSArray with three objects. These three objects are:
{
@"Hi",
@"Hi",
@"Hi"
}
In this case the array contains three strings, which are all equal.
I want to testify for this, I want to create an NSArray category BOOLmethod that loops through all the objects and returns YES if they are all identical. Here is an example:
NSArray *array = [[NSArray alloc] initWithObjects: @"Object", @"Object", @"Object", nil];
if ([array allObjectsAreIdentical /* method I would have to create */) {
NSLog(@"All objects in this array are identical");
}
I am pretty sure that there is no built in method for this, and also I would prefer not to take the tedious route and manually compare each object.
Thanks!
What about
EDIT: Written as
NSArraycategory method this would beNote: You should be aware that this solution (even if it might look elegant) compares more objects in the array than necessary. Therefore, if performance is an issue, you better go with other solutions, e.g. the one proposed by @dieworld.