I am just starting to learn Objective-C programming. I'm developing in Xcode 4.2 on Mac OS X version 10.7.2 on an iMac. I am reading the book "Programming in Objective-C" by Stephen Kochan, which contains a simple "Hello World" example:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello, World!");
[pool drain];
return 0;
}
It bombs out with lots of errors when compiling:
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:313:19: error: unknown type name 'NSString' [1]
There are lots more like this. Is there something that needs to be done before compiling for the first time? Some setup in Xcode?
Unknown typename NSString
means you are passing objective c code to (normal) c compiler
From your code, it looks like you choose the wrong application project to start with. Seems like you choose something that got to do with c program
I suggest you click File -> new project and choose Cocoa Application to start with.
Then You copy your code and put it inside 'didFinishLaunchingWithOptions' method in your appdelegate file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello, World!");
[pool drain];
return YES;
}
Build and run the program. You should be able to see your Hello World in your console log..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With