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

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


  • Follow-Ups:
    • Re: anyObject
      • From: Marco Scheurer <email@hidden>
    • Re: anyObject
      • From: Kurt Revis <email@hidden>
    • Re: Fwd: anyObject
      • From: Ondra Cada <email@hidden>
  • Prev by Date: weird user-default problem
  • Next by Date: Re: Hiding Package Contents
  • Previous by thread: Re: weird user-default problem
  • Next by thread: Re: Fwd: anyObject
  • Index(es):
    • Date
    • Thread