• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finding out if an NSArray's contents are all equal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding out if an NSArray's contents are all equal


  • Subject: Re: Finding out if an NSArray's contents are all equal
  • From: patrick machielse <email@hidden>
  • Date: Sat, 22 Jul 2006 21:25:03 +0200

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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Finding out if an NSArray's contents are all equal
      • From: Andre <email@hidden>
  • Prev by Date: Re: How to track down this memory problem?
  • Next by Date: -stringValue on NSTextfield does not reflect actual contents
  • Previous by thread: Re: Finding out if an NSArray's contents are all equal
  • Next by thread: Re: Finding out if an NSArray's contents are all equal
  • Index(es):
    • Date
    • Thread