• 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: objc_getClassList, pointers, and NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: objc_getClassList, pointers, and NSArray


  • Subject: Re: objc_getClassList, pointers, and NSArray
  • From: David Remahl <email@hidden>
  • Date: Mon, 09 Jul 2001 11:04:41 +0200

> Hey, all.
> I've used the sample code in /usr/include/objc/objc_runtime.h to get a
> list of classes. The sample code is as follows:
>
> int numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
> Class *classes = NULL;
> while (numClasses < newNumClasses) {
> numClasses = newNumClasses;
> classes = realloc(classes, sizeof(Class) * numClasses);
> newNumClasses = objc_getClassList(classes, numClasses);
> }
> // now, can use the classes list; if NULL, there are no classes
> free(classes);
>
> So, that's fine. It suits me perfectly.
>
> Problem is, I want to put the classes into an NSArray (or subclass thereof)
> for use elsewhere in my application. Unfortunately, I missed a great deal
> of the stuff about pointers in my C class due to illness, so I'm not
> entirely clear on procedure here.
>
> I was thinking about pointer arithmetic, but I can't remember how to do
> that, nor can I remember how to be sure I don't overrun the classes buffer.
>
> Pointers are arcane enough when you're just using objects, getting into
> buffers is really weird for me.
>
> Anyhow, thanks in advance for any help you can provide on how to get the
> classes into an NSArray,
>
Hmm, you can use the ususal C array stuff; myArray[elementToGet].

So,

NSMutableArray arrayWithStrings = [[NSMutableArray alloc] init];

for( i=0;i<numClasses;i++)
{
[arrayWithStrings addObject:[NSStringFromClass(classes[i]) retain]];
}

Something like that. From the top of my head, and i'm in a hurry...Could be
way off.

/ david


  • Follow-Ups:
    • Re: objc_getClassList, pointers, and NSArray
      • From: Chris Kane <email@hidden>
References: 
 >objc_getClassList, pointers, and NSArray (From: Rob Rix <email@hidden>)

  • Prev by Date: objc_getClassList, pointers, and NSArray
  • Next by Date: document icons in Cocoa like Image Capture
  • Previous by thread: objc_getClassList, pointers, and NSArray
  • Next by thread: Re: objc_getClassList, pointers, and NSArray
  • Index(es):
    • Date
    • Thread