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
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 mails | Author | Date |
|---|---|---|
| listposter | Jul 22, 17:09 | |
| Ashley Clark | Jul 22, 19:12 | |
| Andre | Jul 22, 19:29 | |
| Adam R. Maxwell | Jul 22, 19:48 | |
| Andre | Jul 22, 20:08 | |
| patrick machielse | Jul 22, 21:25 | |
| Andre | Jul 23, 00:53 | |
| patrick machielse | Jul 23, 01:07 | |
| Andre | Jul 23, 04:14 | |
| Michael Ash | Jul 23, 05:07 |






Cocoa mail archive

