My first Hello world program in Objective-C
Here is my first program that I wrote in Objective-C, and keeping with the tradition, it has to be the Hello World program.
1: /* This is a simple hello world program */
2:
3: /* Includes the systems file Foundation.h that has some
specific classes. */
4: #import <Foundation/Foundation.h>
5:
6: //Begin Execution
7: int main (int argc, const char *argv[])
8: {
9: /* For now, the below code is mainly for memory
management. Reserves space in memory. */
10: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
11: /* NSLog is a function that displays the argument you
pass along with some other information.*/
12: NSLog (@"Hello World");
13: //Release the allocated memory pool
14: [pool drain];
15: //Terminate the execution of main.
16: return 0;
17: }
Since my current background is C#, I am quite happy to find the delimiter ‘;’ is the same in Objective-C;). However what is unsettling to me is the whole memory management. I got really comfortable with .net garbage collection. Commenting style is pretty much the same as others. I mixed up the commenting style to show both styles are possible. Microsoft looks like a saint to me compared to Apple when it comes to forcing me to develop on a MAC. Anyway’s, I will be sharing more code samples, more information in the coming days as I progress through my quest to build the greatest IPhone App.
