如何在 XCode 中编译和运行 Objective-C 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4721628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do compile and run a Objective-C project in XCode?
提问by Jonas
I followed Objective-C beginner's guideand 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.
我遵循了Objective-C 初学者指南并创建了一些文件。然后我在 XCode 中创建了一个空项目并导入了文件。现在我想从 XCode 编译和运行它们。我怎样才能做到这一点?XCode 中的运行/调试菜单选项似乎不可用。
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.
在不使用 Cocoa 的情况下,我应该在 XCode 中使用什么模板在 Objective-C 中编写“Hello World”应用程序?我找不到任何合适的模板。空项目似乎不适用于此。
回答by Matthew Rankin
What template should I use in XCode to write a "Hello World" application in Objective-C not using Cocoa?
在不使用 Cocoa 的情况下,我应该在 XCode 中使用什么模板在 Objective-C 中编写“Hello World”应用程序?
You should create a command line tool with the Foundation framework as follows:
您应该使用 Foundation 框架创建一个命令行工具,如下所示:
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:
我意识到您不想使用 Cocoa,并且我意识到 Foundation 是“包含非 GUI Cocoa 类的框架”。( Learning Objective-C 2.0) 但是,这是以下所有推荐的创建非 GUI Objective-C 应用程序的方法:
- Learn Objective-C on the Macby 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.0by Robert Clair.
- Learn C on the Macby 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."
- Mark Dalrymple 和 Scott Knaster在 Mac 上学习 Objective-C。如第 8 页所述。9、“本书中的所有程序都是基于Foundation框架的。”
- 罗伯特克莱尔的学习 Objective-C 2.0。
- 通过 Dave Mark在 Mac 上学习 C。在第。在第 320 章第 12 章:你从哪里开始,Dave Mark 指出带有 Foundation 框架的命令行工具“是你下一次大冒险的起点——掌握 Objective-C。”
回答by JeremyP
What template should I use in XCode to write a "Hello World" application in Objective-C not using Cocoa?
在不使用 Cocoa 的情况下,我应该在 XCode 中使用什么模板在 Objective-C 中编写“Hello World”应用程序?
You probably want a foundation command line tool.
您可能需要一个基础命令行工具。
In Xcode (assuming 3.2.x) select File/New Project...
在 Xcode(假设 3.2.x)中选择 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
在出现的窗口左侧,选择 Mac OS X 应用程序。右上角的窗格应显示四个选项
- Cocoa application
- Cocoa Applescript application
- Quartz composer application
- Command line tool.
- 可可应用
- 可可 Applescript 应用程序
- 石英作曲家应用程序
- 命令行工具。
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
.
选择命令行工具后,窗格下方应出现下拉列表,您应从中选择foundation
。
That will give you a hello world application which is ready to be compiled and run.
这将为您提供一个可以编译和运行的 hello world 应用程序。
回答by Paul R
Instead of creating a new empty project you should use one of the standard project templates, then add your files to that.
您应该使用标准项目模板之一,而不是创建一个新的空项目,然后将您的文件添加到该模板中。