Skip navigation.
 
mlRe: Finding out if an NSArray's contents are all equal
FROM : patrick machielse
DATE : Sat Jul 22 21:25:03 2006

Op 22-jul-2006, om 19:37 heeft Andre het volgende geschreven:

> What I was looking for was if all objects in an array are equal to 
> each other.
> IOW, are each and every object containing the same equivalent value 
> e.g
> an array of NSNumbers all equalling 21.0 would return YES, else NO 
> if the
> contents' NSNumber objects varied in their value...


You could let NSSet do the hard work for you:

@interface NSArray (IdenticalObjects)
- (BOOL)allObjectsIdentical;
@end

@implementation NSArray (IdenticalObjects)
- (BOOL)allObjectsIdentical
{
    return [[NSSet setWithArray:self] count] == 2;
}
@end

patrick

Related mailsAuthorDate
mlFinding out if an NSArray's contents are all equal listposter Jul 22, 17:09
mlRe: Finding out if an NSArray's contents are all equal Ashley Clark Jul 22, 19:12
mlRe: Finding out if an NSArray's contents are all equal Andre Jul 22, 19:29
mlRe: Finding out if an NSArray's contents are all equal Adam R. Maxwell Jul 22, 19:48
mlRe: Finding out if an NSArray's contents are all equal Andre Jul 22, 20:08
mlRe: Finding out if an NSArray's contents are all equal patrick machielse Jul 22, 21:25
mlRe: Finding out if an NSArray's contents are all equal Andre Jul 23, 00:53
mlRe: Finding out if an NSArray's contents are all equal patrick machielse Jul 23, 01:07
mlRe: Finding out if an NSArray's contents are all equal Andre Jul 23, 04:14
mlRe: Re: Finding out if an NSArray's contents are all equal Michael Ash Jul 23, 05:07