简体   繁体   English

Xcode 9.4.1和Foundation Framework

[英]Xcode 9.4.1 and Foundation Framework

Hello I'm new to programming in Objective-C. 您好,我是Objective-C编程的新手。 I'm reading the book "Programing in Objective-C Developers Library" and they're asking me to create a command line project using the foundation framework, but when I go to create one, I don't see an option to use Foundation. 我正在阅读《 Objective-C开发人员库中的编程》一书,他们要我使用基础框架创建命令行项目,但是当我创建一个命令行项目时,看不到使用Foundation的选择。

图片1

图片2

Your first screen shot shows it: 您的第一个屏幕截图显示了它:

在此处输入图片说明

You've already selected Command Line Tool, which is correct. 您已经选择了命令行工具,这是正确的。 So now click Next and you will be creating a command line tool that uses the Foundation framework. 因此,现在单击“下一步”,您将创建一个使用Foundation框架的命令行工具。 In your second screen shot, enter a name for the tool and click Next; 在第二个屏幕快照中,输入工具的名称,然后单击“下一步”。 you will then be asked for a place to Save this project. 然后将要求您提供保存该项目的位置。 Do so. 这样做。 When you do, the code for main.m will say: 完成后, main.m的代码将显示:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
    }
    return 0;
}

See that first line? 看到第一行吗? That is "using the Foundation framework". 那就是“使用基金会框架”。

One thing to know is that Foundation is so important in Objective-C that it's practically part of the language. 要知道的一件事是,Foundation在Objective-C中是如此重要,实际上它是该语言的一部分。 It provides classes like NSNumber , NSString , NSArray , NSDictionary , and many others that we assume are always available. 它提供了诸如NSNumberNSStringNSArrayNSDictionary类的类,并且我们假设许多其他类总是可用的。 So Foundation is special in that every Objective-C project will use it, and it'll be included in any project templates like the Command Line Tool template you're working from. 因此,Foundation的特殊之处在于,每个Objective-C项目都将使用它,并且它将包含在您正在使用的任何项目模板(例如,命令行工具模板)中。 Other project templates will include additional frameworks (eg the Cocoa App template will set up your project with AppKit for you), and if you want to use other frameworks you'll add them yourself after you create the project. 其他项目模板将包括其他框架(例如Cocoa App模板将为您使用AppKit设置您的项目),并且如果您想使用其他框架,则可以在创建项目后自行添加它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM