Programming in Objective-C


Programming in Objective-C


In this chapter, we dive right in and show you how to write your first Objective-C program. You won’t work with objects just yet; that’s the topic of the next
chapter. We want you to understand the steps involved in keying in a program and compiling and running it.
To begin, let’s pick a rather simple example: a program that displays the phrase “Programming is fun!” on your screen. Without further ado, Program 2.1
shows an Objective-C program to accomplish this task.
Program 2.1
// First program example
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSLog (@"Programming is fun!");
}
return 0;
}
Compiling and Running Programs
Before we go into a detailed explanation of this program, we need to cover the steps involved in compiling and running it. You can both compile and run
your program using Xcode, or you can use the Clang Objective-C compiler in a Terminal window. Let’s go through the sequence of steps using both
methods. Then you can decide how you want to work with your programs throughout the rest of this book.
Note
You’ll want to go to developer.apple.com and make sure you have the latest version of the Xcode development tools. There you can download
Xcode and the iOS SDK at no charge. If you’re not a registered developer, you’ll have to register first. That can also be done at no charge. Note
that Xcode is also available for a minimal cost from the Mac App Store.
Using Xcode
Xcode is a sophisticated application that enables you to easily type in, compile, debug, and execute programs. If you plan on doing serious application
development on the Mac, learning how to use this powerful tool is worthwhile. We just get you started here. Later we return to Xcode and take you through
the steps involved in developing a graphical application with it.
Note
As mentioned, Xcode is a sophisticated tool, and the introduction of Xcode 4 added even more features. It’s easy to get lost using this tool. If
that happens to you, back up a little and try reading the Xcode User Guide, which can be accessed from Xcode help menu, to get your bearings.
Xcode is located in the Developer folder inside a subfolder called Applications. Figure 2.1 shows its icon.
Figure 2.1. Xcode icon
2.1 Xcode


Comments

Popular posts from this blog

Convert HtmlToPDF in ASP.net & iTextshrap

Create Pivot Table In C#

How to Display Page Wise Total Amount & Grand Total Amount in Last page SSRS & RDLC Report