• 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: Unique strings array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unique strings array


  • Subject: Re: Unique strings array
  • From: Roland King <email@hidden>
  • Date: Sat, 12 Mar 2011 10:42:07 +0800

On 12-Mar-2011, at 10:33 AM, Stevo Brock wrote:

> Unless I'm missing something, if you have aWord1 = @"the" and aWord2 = @"the", they will both get added to the array/set.
>

You're missing something. Sets use isEqual and aWord1 and aWord2 are 'equal' to each other so only one gets added and the second one gets ignored.

> You can also use an NSMutableDictionary - just
>
> for (NSString* word in wordsArray)
> 	[dict setObject:anything forKey:word];
>
> NSArray*	uniqueWords = [dict allKeys];
>

NSDictionary uses exactly the same method of figuring out whether something already exists in as NSSet does. So all your example does is do the same thing but use more memory doing it because the NSDictionary has to keep the values you don't need.

NSSet is what you want for this.

Roland


> -Stevo
>
>
> On Mar 11, 2011, at 6:19 PM, Dave DeLong wrote:
>
>> Use an NSMutableSet instead. That should have constant lookup time instead of linear (like an array usually is).
>>
>> Dave


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Unique strings array
      • From: Leonardo <email@hidden>
References: 
 >Unique strings array (From: Leonardo <email@hidden>)
 >Re: Unique strings array (From: Dave DeLong <email@hidden>)
 >Re: Unique strings array (From: Stevo Brock <email@hidden>)

  • Prev by Date: Re: Unique strings array
  • Next by Date: Re: Core Data NSPredicate
  • Previous by thread: Re: Unique strings array
  • Next by thread: Re: Unique strings array
  • Index(es):
    • Date
    • Thread