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

Re: anyObject


  • Subject: Re: anyObject
  • From: Marco Scheurer <email@hidden>
  • Date: Thu, 31 Jan 2002 18:15:24 +0100

On Thursday, January 31, 2002, at 05:52 pm, Robert Goldsmith wrote:

The "randomness" means there is no way to tel before which object will be
returned, *NOT* that it would or should be a different one each time.


So the docs are misleading?

Yes

Ok, then if I want to select a random object from a set, what do you suggest? I don't need the objects to be ordered in any way. Storing them in an array then using a random number to access an index seems silly when anyObject would have been such a good way to do it!

Why? It seems reasonbale to me. anyObject is useful when you need one representant from the set, and there is no need to complicate it with a pseudo random generator.

On the other side, you could implement your -randomObject method in a category of NSArray, and there you go.

On the topic of having your items ordered or not. The true test on using a Set is do you need (mathematical) set functionality? Or, on an array, would you be calling often -indexOfObject: ? Otherwise, if you just need any kind of storage for your objects, you are better of with NSArray: it is faster and takes less memory.

Marco Scheurer
Sen:te, Lausanne, Switzerland http://www.sente.ch


References: 
 >Re: anyObject (From: Robert Goldsmith <email@hidden>)

  • Prev by Date: Re: weird user-default problem
  • Next by Date: NSDocument: revertDocumentToSaved problem
  • Previous by thread: Re: anyObject
  • Next by thread: Re: anyObject
  • Index(es):
    • Date
    • Thread