I'm learning how to use the Objective-C runtime function. To do this, I used Xcode Version 4.6.2 (4H1003) and chose from the OS X's Foundation template to create a new project with sample code I found in Apple's documentation.
There are only three files in the project.
main.m
#import <Foundation/Foundation.h> #include "ObjectiveCRuntime.h"
int main(int argc, const char * argv[]) { @autoreleasepool { listObjectiveC_ClassesUsedInThisApp(); } return 0; }
ObjectiveCRuntime.h
#ifndef ObjCWithoutCocoa_ObjectiveCRuntime_h #define ObjCWithoutCocoa_ObjectiveCRuntime_h
void listObjectiveC_ClassesUsedInThisApp(void); /* list Objective-C classes used by this executable */
#endif
and ObjectiveCRuntime.c
#import <Foundation/Foundation.h> #import <Foundation/NSObjCRuntime.h> #import "ObjectiveCRuntime.h"
extern int objc_getClassList(Class *buffer, int bufferLen);
/* list Objective-C classes used by this executable */ void listObjectiveC_ClassesUsedInThisApp(void) { int numClasses; Class * classes = NULL;
classes = NULL; numClasses = objc_getClassList(NULL, 0);
if (numClasses > 0 ) { classes = malloc(sizeof(Class) * numClasses); numClasses = objc_getClassList(classes, numClasses); printf("This application has %u classes. Note that you cannot assume these classes inherit from NSObject.\n", numClasses); free(classes); } }
When I build, Xcode emits build fail errors <XcodeScreenSnapz001.jpeg>
Since Apple provided headers shouldn't be the source of errors, I'm not sure where to start looking for the error. The ObjectiveCRuntime.c and main.m are listed in the Target's Build Phases under Compile Sources.
Thanks for any hints.
|