Jonas
Jonas

Reputation: 128777

How do compile and run a Objective-C project in XCode?

I followed Objective-C beginner's guide and created a few files. Then I created an Empty Project in XCode and imported the files. Now I want to compile and run them from XCode. How can I do that? The Run/Debug menu option in XCode doesn't seem to be available.

What template should I use in XCode to write a "Hello World" application in Objective-C not using Cocoa? I can't find any appropriate template. The Empty Project doesn't seem to work for this.

Upvotes: 2

Views: 9229

Answers (3)

Matthew Rankin
Matthew Rankin

Reputation: 461167

What template should I use in XCode to write a "Hello World" application in Objective-C not using Cocoa?

You should create a command line tool with the Foundation framework as follows: alt text

I realize that you don't want to use Cocoa, and I realize that Foundation is the "framework that contains the non-GUI Cocoa classes." (Learning Objective-C 2.0) However, this is the recommended method for creating a non-GUI Objective-C application by all of the following:

  • Learn Objective-C on the Mac by Mark Dalrymple and Scott Knaster. As stated on p. 9, "All the programs in this book are based on the Foundation framework."
  • Learning Objective-C 2.0 by Robert Clair.
  • Learn C on the Mac by Dave Mark. On p. 320 in Chapter 12: Where Do You Go from Here, Dave Mark states that the command line tool with the Foundation framework "is the starting point for your next big adventure—mastering Objective-C."

Upvotes: 8

JeremyP
JeremyP

Reputation: 86651

What template should I use in XCode to write a "Hello World" application in Objective-C not using Cocoa?

You probably want a foundation command line tool.

In Xcode (assuming 3.2.x) select File/New Project...

In the window that appears, on the left hand side, select Mac OS X application. The top right hand pane should display four options

  • Cocoa application
  • Cocoa Applescript application
  • Quartz composer application
  • Command line tool.

It's the last option you want.

Having selected command line tool, a drp down list should appear below the pane, from which you should select foundation.

That will give you a hello world application which is ready to be compiled and run.

Upvotes: 4

Paul R
Paul R

Reputation: 212929

Instead of creating a new empty project you should use one of the standard project templates, then add your files to that.

Upvotes: 1

Related Questions