objc_getClassList, pointers, and NSArray
objc_getClassList, pointers, and NSArray
- Subject: objc_getClassList, pointers, and NSArray
- From: Rob Rix <email@hidden>
- Date: Mon, 9 Jul 2001 04:39:50 -0400
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,
-- Rob
Murphy strikes again!