Re: Understanding Xcode build errors from using Objective-C runtime function in OS X's Foundation app template.
Re: Understanding Xcode build errors from using Objective-C runtime function in OS X's Foundation app template.
- Subject: Re: Understanding Xcode build errors from using Objective-C runtime function in OS X's Foundation app template.
- From: Public <email@hidden>
- Date: Fri, 31 May 2013 01:46:52 +0800
George, thanks for responding and helpful answer.
I was dumbfounded before noticing my filename error. You're absolutely right and thanks for the tip on changing source file type.
Have a great week!
:) Chris
On May 31, 2013, at 1:38 AM, George Warner <email@hidden> wrote:
> On May 29, 2013, at 9:32 PM, email@hidden wrote:
>> 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.
>
> I didn't see your jpeg file (<XcodeScreenSnapz001.jpeg>) but when I put your code into an empty Xcode project I only got one build error and fixed it by typecasting malloc's returned value to (Class *).
>
> void listObjectiveC_ClassesUsedInThisApp(void)
> {
> int numClasses;
> Class * classes = NULL;
>
> classes = NULL;
> numClasses = objc_getClassList(NULL, 0);
>
> if (numClasses > 0 )
> {
> classes = (Class *) malloc(sizeof(Class) * numClasses); // <<== added typecast to (Class *)
> 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);
> }
> }
>
> Note: I also changed your source file's ("ObjectiveCRuntime.c") extension to ".m" (ObjectiveCRuntime.m); otherwise Xcode tried to compile the Foundation and ObjectiveCRuntime (ObjC) headers with C instead of ObjC; you can also fix this by selecting your source file in your project's "Project Navigator" view and then in the "File Inspector" view change your source files type to "Objective-C Source".
>
>
> --
> Enjoy,
> George Warner, x4-0668
> Schizophrenic Optimization Scientist
> Apple Developer Technical Support (DTS)
> eMail: <email@hidden>
> iChat: <email@hidden>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden