Extending “Hello, World!”

Now that you understand how the “Hello World” program works, let’s add the phrase “I’m ready to program in Objective-C!” to the output. Simply add another NSLog statement to the program. The solution is below, but try to figure out the problem for yourself.

/* Add the phrase
"I'm ready to program in Objective-C!"
to the output */

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSLog (@"Hello, World!");
        NSLog (@"I'm ready to program in Objective-C!");

        [pool drain];
        return 0;

Build and Run the program. The output should be the same as below:

Hello, World!
I'm ready to program in Objective-C!

The NSLog calls automatically create a paragraph break, or a new line, between subsequent calls. It does this automatically, but you can also force a new line in the middle of an NSLog call by using \n anywhere in the line of output. Therefore,

NSLog (@"Hello, World! \nI'm ready to program in Objective-C!");

Produces the same output as above.

Leave a comment

1 Comment

  1. Learn Objective-C in 24 Days « Programming for iOS

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

  • Welcome

    My goal is to make CupsOfCocoa into a beautiful source for beginners to the iPhone platform to get started. Subscribe below for more, and stay tuned!

  • Contact Me

    If you need to contact me for any reason, feel free to send me an email.
  • The Giving Spirit

    If you've found this site helpful, would you consider donating a little sum? Any amount is appreciated...Thanks so much!

  • Roadmap

  • Enter your email address to follow this blog and receive notifications of new posts by email.

    Join 222 other followers

  • Back to the Past

    September 2010
    S M T W T F S
    « Aug   Oct »
  • Time Machine

  • You count!

  • Worldwide Stats

    free counters
  • Advertisements
%d bloggers like this: