Re: anyObject
Re: anyObject
- Subject: Re: anyObject
- From: <email@hidden>
- Date: Thu, 31 Jan 2002 11:04:04 -0600
Robert,
>
I am trying to use the NSSet method anyObject which, according
>
to the docs, returns a random object selected from the set or,
>
if the set is empty, nil.
>
>
However, the following lines of code don't seem to do that:
>
>
[ ...code not quoted... ]
>
>
The result of this run is, in fact:
>
>
2002-01-31 16:09:16.979 Mind[7601] <NSCFSet: 0x6bd30>
>
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
>
Size of the set is 10
>
>
(which shows the values have been stored ok) followed by 100
>
selections of the the NSNumber object that holds the value 0.
This is what the documentation says about anyObject:
"Returns one of the objects in the receiver (essentially chosen at
random), or nil if the receiver contains no objects."
If I interpret this correctly, this is not to be used for
random-drawing like situations. Rather, "chosen at random" just
means that you cannot make any assumptions as to which of the
objects in your set will be returned.
The anyObject method can be useful if an algorithm simply needs
an object from the set but doesn't care which one it is.
Regards,
Martin