Fwd: anyObject
Fwd: anyObject
- Subject: Fwd: anyObject
- From: Robert Goldsmith <email@hidden>
- Date: Thu, 31 Jan 2002 16:30:21 +0000
Hi :)
I have searched the archives but there seems no mention of this
problem - sorry if it has been discussed before.
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:
int main (int argc, const char * argv[])
{
int i;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableSet *temp=[NSMutableSet setWithCapacity:10];
for(i=0;i<10;i++)
[temp addObject:[NSNumber numberWithInt:i]];
NSLog([temp description]);
printf("Size of the set is %i\n",[temp count]);
for(i=0;i<100;i++)
printf("Random selection number %i is %i\n",i,[[temp anyObject]
intValue]);
[pool release];
return 0;
}
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.
Any suggestions?
Robert Goldsmith