Changes

Jump to: navigation, search

Installing Xcode and Compiling Objective-C on Mac OS X

1,303 bytes added, 19:37, 25 September 2009
Starting a New Project
* In the main panel, choose ''Foundation Tool'' then click on the ''Choose..'' button.
* In the resulting panel, enter "SampleAppsampleApp'' in the ''Save As:'' field.
By default, Xcode will put the project files in your ''Documents'' folder so be sure to create and specify a specific folder for your Objective-C development work before proceeding by clicking the ''Save'' button. Xcode will subsequently create the new project and open the main Xcode window:
[[Image:xcode_main_window.jpg|The main Xcode window]]
 
== Writing an Objective-C Application with Xcode ==
 
Xcode will create skeleton versions of the files needed to build a command-line based Objective-C application. Objective-C source files are identified by the ''.m'' filename extension. In the case of our example, Xcode and pre-created a main source file named '' sampleApp.m'' and populated with some based code ready for us to edit. To view the code, select ''sampleApp.m'' from the list of files so that the code appears in the editor area. The skeleton code reads as follows:
 
<pre>
#import <Foundation/Foundation.h>
 
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
// insert code here...
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
</pre>
 
Modify the ''NSLog'' line so that it reads:
 
<pre>
NSLog(@"This is my first Objective-C App!");
</pre>
 
With the change made, the next step is to compile and run the application by selecting the ''Build and Run'' option located in the Xcode ''Build'' menu. Once this option has been selected, Xcode will compile the sources and run the application within a terminal window:
 
 
[[Image:xcode_running_sample_app.jpg|Running a sample Objective-C application in Xcode]]
 
 
== Compiling Objective-C from the Command Line ==

Navigation menu