2

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.

6
  • 1
    There are extensive guides available via the Help menu Commented Jan 18, 2011 at 7:50
  • @trojanfoe: I only find guides using Cocoa, not only Objective-C. Commented Jan 18, 2011 at 8:03
  • @trojanfoe: Where in the documentation can I find instructions for running a simple Hello World coded in Objective-C using XCode? Commented Jan 18, 2011 at 8:40
  • @Jonas: Here: developer.apple.com/library/mac/documentation/DeveloperTools/… Commented Jan 18, 2011 at 8:53
  • @Jonas: The guide you linked uses the Cocoa Foundation framework. You're drawing a distinction that isn't there. Commented Jan 18, 2011 at 8:55

3 Answers 3

8

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."
Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

1

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

2 Comments

What project type should I use? I'm not using Cocoa, and on the command line project only C is available as language, not Objective-C. Can't I follow this tutorial using XCode?
@Jonas: The "Foundation Tool" project type is an Objective-C command-line tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.