Objective-C 和 Cocoa 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/435928/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:02:28  来源:igfitidea点击:

What's the difference between Objective-C and Cocoa?

objective-ccocoa

提问by Pat Notz

I'm just learning Objective-C/Cocoa programming for the Mac. All of the tutorials, books, blogs, podcasts, etc. I've been using really cover the two together. Is there an easy way to tell which pieces are vanilla Objective-C and which come from Cocoa?

我只是在为 Mac 学习 Objective-C/Cocoa 编程。我一直在使用的所有教程、书籍、博客、播客等都涵盖了两者。有没有一种简单的方法可以分辨哪些部分是香草 Objective-C,哪些来自 Cocoa?

回答by Jason Coco

Objective-C is the language... it defines all the things like the keywords for defining objects, the syntax for messaging object, things like that.

Objective-C 是一种语言……它定义了所有的东西,比如定义对象的关键字、消息对象的语法等等。

Cocoa is a development framework (it's actually an umbrella framework which combines three other frameworks, Foundation, AppKit and CoreData).

Cocoa 是一个开发框架(它实际上是一个伞形框架,它结合了其他三个框架,Foundation、AppKit 和 CoreData)。

These frameworks (Cocoa) define all the objects that are nice to use and interact with the operating system, as well as a number of functions. For example, Cocoa defines things like NSStringand NSObject. Cocoa can currently be used with other language bindings, such as python or ruby, and used to be used with Java as well. So, if you were using Cocoa with Java, you would still get an NSStringobject, but you would call and use it from within a Java application.

这些框架 (Cocoa) 定义了所有易于使用并与操作系统交互的对象,以及许多功能。例如,Cocoa 定义了像NSString和这样的东西NSObject。Cocoa 目前可以与其他语言绑定一起使用,例如 python 或 ruby​​,并且过去也可以与 Java 一起使用。因此,如果您将 Cocoa 与 Java 一起使用,您仍然会得到一个NSString对象,但您将在 Java 应用程序中调用和使用它。

Without linking to one of the Cocoa frameworks, Objective-C comes with only a very basic Object class as a pre-defined root class.

没有链接到 Cocoa 框架之一,Objective-C 只附带一个非常基本的 Object 类作为预定义的根类。

回答by igowen

Objective-C is the language itself.

Objective-C 是语言本身。

Cocoa, formerly NextStep, is the API and runtime that sits on top of Obj-C. Anything starting with NS (for NextStep) is part of Cocoa, not part of the language.

Cocoa,以前称为 NextStep,是位于 Obj-C 之上的 API 和运行时。任何以 NS(用于 NextStep)开头的东西都是 Cocoa 的一部分,而不是语言的一部分。

回答by rkj

Sure, it is quite easy - Objective-C is the language, Cocoa is the API/library you are using to build you Mac App.

当然,这很容易——Objective-C 是语言,Cocoa 是您用来构建 Mac 应用程序的 API/库。

回答by Chuck

Look in /usr/include/objc/ — in there is pure Objective-C. Everything else is Cocoa. You might notice you almost never directly use anything in there.

查看 /usr/include/objc/ — 里面有纯 Objective-C。其他的都是可可。您可能会注意到您几乎从不直接使用其中的任何内容。

However, in practice it makes little difference. Cocoa is the de facto Objective-C standard library. The only platform where Objective-C is used without Cocoa is Portable Object Compiler, and I'm guessing maybe three people still use that.

然而,在实践中它没有什么区别。Cocoa 是事实上的 Objective-C 标准库。在没有 Cocoa 的情况下使用 Objective-C 的唯一平台是Portable Object Compiler,我猜可能还有三个人在使用它。