This question pops up quite often here, even if just implicitly when users mistag their iOS questions. So, what’s the difference between Xcode, Objective-C and Cocoa?
这个问题经常出现在这里,即使是当用户在iOS问题上出错时。那么Xcode, Objective-C和Cocoa有什么区别呢?
3 个解决方案
#1
32
Objective-C is a programming language. It could be said that it’s just a description of what valid Objective-C programs look like and what they mean. If you have a source code listing written in Objective-C, you need an interpreter or a compiler to put the listing to work. Languages like Objective-C are usually compiled, so most people use a compiler (like LLVM). Objective-C is almost exclusively used to develop for iOS and OS X, but there are other uses, too – as an example, some people write Objective-C for Linux.
Objective-C是一种编程语言。可以说,它只是对Objective-C程序的描述以及它们的含义。如果您有一个用Objective-C编写的源代码清单,您需要一个解释器或编译器来运行清单。Objective-C之类的语言通常是编译的,所以大多数人使用编译器(比如LLVM)。Objective-C几乎只用于iOS和OS X开发,但也有其他用途——例如,有人为Linux编写Objective-C。
You can use a text editor to write the sources and a compiler to turn them into an actual programs, but with modern technologies there’s much more to take care of, so that there is another program to make your job easier. These are called Integrated Development Environments, or IDEs. An IDE offers you a convenient way to edit the sources, compile them, debug the resulting programs, read the documentation, and many other things. Xcode is one such IDE. An important observation here is that Xcode does not compile your sources itself, it just calls the standalone compiler (LLVM). And Xcode is not the only IDE you can use to develop Objective-C apps – there’s AppCode, for example.
您可以使用文本编辑器编写源文件,使用编译器将它们转换为实际的程序,但是使用现代技术需要处理更多的内容,这样就有了另一个程序来简化您的工作。这些被称为集成开发环境(ide)。IDE为您提供了一种方便的方式来编辑源代码、编译它们、调试结果程序、阅读文档和其他许多东西。Xcode就是这样的IDE。这里的一个重要观察是,Xcode并不编译源代码本身,它只调用独立编译器(LLVM)。Xcode并不是开发Objective-C应用程序的唯一IDE,比如有AppCode。
Writing iOS or OS X apps from scratch each time would be very time-consuming. That’s why Apple provides the developers with a good set of libraries. The libraries are simply a huge amount of source code written by Apple, and this source code takes care of most things that apps have in common. These libraries are called Cocoa.
每次从头编写iOS或OS X应用程序都非常耗时。这就是为什么苹果为开发者提供了一套很好的库。这些库只是由苹果编写的大量源代码,而这些源代码则负责应用程序的大多数共同之处。这些库称为Cocoa。
Now, if you can’t figure out how to extend a class, you are most probably talking about Objective-C. It doesn’t have anything to do with Xcode or Cocoa, you could be very well writing some GNUstep code for Linux using Vim as an IDE and GCC as a compiler. On the other hand, if your Xcode build process fails because of some mysterious setting, or if you’re trying to build a static library in Xcode, that’s clearly an Xcode issue. And if you can’t figure out how to use some NSObject facility or the NSFileManager class, that’s Cocoa. (But it doesn’t have to be Xcode-related, as you could use AppCode or TextMate as your IDE!)
如果你不知道如何扩展一个类,你很可能是在说Objective-C。它与Xcode或Cocoa没有任何关系,您可以很好地为Linux编写一些GNUstep代码,使用Vim作为IDE,使用GCC作为编译器。另一方面,如果您的Xcode构建过程由于某些神秘的设置而失败,或者如果您试图在Xcode中构建静态库,那么这显然是一个Xcode问题。如果你不知道如何使用NSObject或者NSFileManager类,那就是Cocoa。(但它不必与xcode相关,因为您可以使用AppCode或TextMate作为IDE!)
Originally available on my blog. Feel free to link to the blog post or this question when retagging or explaining the difference.
最初可以在我的博客上找到。在复述或解释差异时,请随意链接到博客文章或这个问题。
#2
6
Xcode is the integrated development environment (IDE)—the application—that developers use to write software for iOS and/or OS X. It includes the editor, the build system (determining what to build to produce the desired target), and quite a few other things.
Xcode是集成开发环境(IDE)——开发人员用来为iOS和/或OS x编写软件的应用程序。
Objective-C is the main language that developers write such software in. They may write bits of it in pure C, use C++ or combine it with Objective-C (producing Objective-C++), or write some or all of the program in another language entirely, such as MacRuby, Java (with j2objc), or C# (with MonoTouch).
Objective-C是开发人员编写此类软件的主要语言。他们可以用纯C编写一些程序,使用c++,或者将其与Objective-C(生成Objective-C+)结合,或者完全用另一种语言编写一些或全部程序,如MacRuby、Java(带有j2objc)或c#(带有MonoTouch)。
Xcode includes the Clang compiler, which turns code written in Objective-C, C, and a few other languages into executable code. Most error messages come from Clang, and Xcode relies heavily on it for search indexing, syntax highlighting, and name completion of Objective-C code.
Xcode包括Clang编译器,它将用Objective-C、C和其他一些语言编写的代码转换为可执行代码。大多数错误消息都来自Clang, Xcode在搜索索引、语法突出显示和Objective-C代码的名称完成方面非常依赖它。
Cocoa and Cocoa Touch are application frameworks. Each one is a suite of many individual frameworks (libraries stored in folders named blahblah.framework), such as:
Cocoa和Cocoa触摸是应用程序框架。每个框架都是许多独立框架的集合(库存储在名为blahblah.framework的文件夹中),例如:
- Foundation (both): General object-oriented utilities, including NSString, NSURL, NSFileManager, etc.
- Core Foundation (both): Mostly the same thing, but different, mainly in having a C-based API rather than Objective-C
- Core Foundation(两者):基本相同,但不同,主要是基于c的API而不是Objective-C
- 基础(两者):一般的面向对象实用程序,包括NSString、NSURL、NSFileManager等
- Application Kit (Mac): Application and windowing framework
- 应用工具包(Mac):应用程序和窗口框架
- UIKit (iOS): Application and windowing framework
- UIKit (iOS):应用程序和窗口框架
- Core Graphics (both): Drawing
- 核心图形(两个):画
- Core Animation (both): Sprite-management and animation framework
- 核心动画(两个):Sprite-management和动画框架。
(and many, many more where they came from, especially on the Mac)
(还有很多人,尤其是在Mac电脑上)
So:
所以:
- You can use a framework besides Cocoa or Cocoa Touch, but you'll have to have some Cocoa/Cocoa Touch code, at some level, in order for your application to talk to the system, receive events, draw, etc. Frameworks that specifically target Mac and/or iOS will include the relevant wrappers for you, at varying levels of quality.
- 您可以使用一个框架除了可可和可可,但是你必须有一些可可/接触代码,在某种程度上,为了使您的应用程序和系统,接收事件,画画,等等。框架专门针对Mac和/或iOS将包括有关包装,在不同等级的品质。
- You can use a language besides Objective-C, but you'll have lots of syntactic awkwardness, as most of Cocoa and Cocoa Touch are designed for Objective-C's unique syntactic features (particularly selectors).
- 除了Objective-C之外,你还可以使用一种语言,但是你会有很多语法上的尴尬,因为大多数的Cocoa和Cocoa Touch都是为Objective-C的独特的句法特性而设计的(特别是选择器)。
- You can use an editor besides Xcode, and you can even use a build system besides Xcode (such as make), but Apple's App Stores expect apps built a particular way (especially with regard to code signing), so unless you're not targeting the App Stores, any other build system has to replicate what Xcode does or risk its users getting rejections.
- 除了Xcode,您可以使用一个编辑器,您甚至可以使用构建系统除了Xcode(比如做),但是苹果的应用程序商店预计应用程序建立了一个特定的方式(特别是关于代码签名),所以除非你不是针对应用程序商店,其他构建系统复制什么Xcode或风险用户被拒绝。
#3
1
A clear mistake is failing to differentiate Xcode from everything else. Xcode is the tool you are using to program in - to edit code, run code, etc. So if you are having trouble with the tool (e.g., the window doesn't show you your code properly, or you're having trouble drawing your interface, etc.), that's an Xcode problem.
一个明显的错误是没有把Xcode和其他东西区分开来。Xcode是你用来编程的工具——用来编辑代码、运行代码等等。所以如果你在使用这个工具时遇到了麻烦(例如,窗口没有正确地显示你的代码,或者你在绘制界面时遇到了麻烦,等等),这就是Xcode的问题。
If you don't understand why your code doesn't work, you're probably having an Objective-C problem or a Cocoa problem. But you won't necessarily know which.
如果您不理解代码为什么不能工作,那么您可能遇到了Objective-C问题或Cocoa问题。但你不一定知道。
-
It's an Objective-C problem if the root of your trouble is that you don't know how the language works (e.g. you don't know what the asterisk is for, or that declaration is not instantiation, or that messages to nil do not error out but don't do anything either).
如果问题的根源在于您不知道语言是如何工作的,那么这就是Objective-C问题(例如,您不知道星号是做什么的,或者声明不是实例化的,或者发送到nil的消息不会出错,但也不会做任何事情)。
-
It's a Cocoa problem if you don't grasp the delegate architecture or how a view controller works.
如果您不掌握委托架构或视图控制器的工作方式,那么这就是一个Cocoa问题。
But my experience of the way people pose questions is that you may be ignorant of which of these you are ignorant of. I don't mean you personally, I mean all of us. This can make it difficult to pose the question properly because you don't know what exactly it is that you don't know — if you did, you'd know it and you probably wouldn't be having a problem (you'd be fixing the problem and on to the next thing).
但我对人们提出问题的方式的经验是,你可能不知道你所不知道的这些。我不是指你,我是指我们所有人。这可能会让你很难恰当地提出问题,因为你不知道你不知道确切的是什么——如果你知道了,你就知道了,你可能就不会有问题了(你会解决问题,接着做下一件事)。
#1
32
Objective-C is a programming language. It could be said that it’s just a description of what valid Objective-C programs look like and what they mean. If you have a source code listing written in Objective-C, you need an interpreter or a compiler to put the listing to work. Languages like Objective-C are usually compiled, so most people use a compiler (like LLVM). Objective-C is almost exclusively used to develop for iOS and OS X, but there are other uses, too – as an example, some people write Objective-C for Linux.
Objective-C是一种编程语言。可以说,它只是对Objective-C程序的描述以及它们的含义。如果您有一个用Objective-C编写的源代码清单,您需要一个解释器或编译器来运行清单。Objective-C之类的语言通常是编译的,所以大多数人使用编译器(比如LLVM)。Objective-C几乎只用于iOS和OS X开发,但也有其他用途——例如,有人为Linux编写Objective-C。
You can use a text editor to write the sources and a compiler to turn them into an actual programs, but with modern technologies there’s much more to take care of, so that there is another program to make your job easier. These are called Integrated Development Environments, or IDEs. An IDE offers you a convenient way to edit the sources, compile them, debug the resulting programs, read the documentation, and many other things. Xcode is one such IDE. An important observation here is that Xcode does not compile your sources itself, it just calls the standalone compiler (LLVM). And Xcode is not the only IDE you can use to develop Objective-C apps – there’s AppCode, for example.
您可以使用文本编辑器编写源文件,使用编译器将它们转换为实际的程序,但是使用现代技术需要处理更多的内容,这样就有了另一个程序来简化您的工作。这些被称为集成开发环境(ide)。IDE为您提供了一种方便的方式来编辑源代码、编译它们、调试结果程序、阅读文档和其他许多东西。Xcode就是这样的IDE。这里的一个重要观察是,Xcode并不编译源代码本身,它只调用独立编译器(LLVM)。Xcode并不是开发Objective-C应用程序的唯一IDE,比如有AppCode。
Writing iOS or OS X apps from scratch each time would be very time-consuming. That’s why Apple provides the developers with a good set of libraries. The libraries are simply a huge amount of source code written by Apple, and this source code takes care of most things that apps have in common. These libraries are called Cocoa.
每次从头编写iOS或OS X应用程序都非常耗时。这就是为什么苹果为开发者提供了一套很好的库。这些库只是由苹果编写的大量源代码,而这些源代码则负责应用程序的大多数共同之处。这些库称为Cocoa。
Now, if you can’t figure out how to extend a class, you are most probably talking about Objective-C. It doesn’t have anything to do with Xcode or Cocoa, you could be very well writing some GNUstep code for Linux using Vim as an IDE and GCC as a compiler. On the other hand, if your Xcode build process fails because of some mysterious setting, or if you’re trying to build a static library in Xcode, that’s clearly an Xcode issue. And if you can’t figure out how to use some NSObject facility or the NSFileManager class, that’s Cocoa. (But it doesn’t have to be Xcode-related, as you could use AppCode or TextMate as your IDE!)
如果你不知道如何扩展一个类,你很可能是在说Objective-C。它与Xcode或Cocoa没有任何关系,您可以很好地为Linux编写一些GNUstep代码,使用Vim作为IDE,使用GCC作为编译器。另一方面,如果您的Xcode构建过程由于某些神秘的设置而失败,或者如果您试图在Xcode中构建静态库,那么这显然是一个Xcode问题。如果你不知道如何使用NSObject或者NSFileManager类,那就是Cocoa。(但它不必与xcode相关,因为您可以使用AppCode或TextMate作为IDE!)
Originally available on my blog. Feel free to link to the blog post or this question when retagging or explaining the difference.
最初可以在我的博客上找到。在复述或解释差异时,请随意链接到博客文章或这个问题。
#2
6
Xcode is the integrated development environment (IDE)—the application—that developers use to write software for iOS and/or OS X. It includes the editor, the build system (determining what to build to produce the desired target), and quite a few other things.
Xcode是集成开发环境(IDE)——开发人员用来为iOS和/或OS x编写软件的应用程序。
Objective-C is the main language that developers write such software in. They may write bits of it in pure C, use C++ or combine it with Objective-C (producing Objective-C++), or write some or all of the program in another language entirely, such as MacRuby, Java (with j2objc), or C# (with MonoTouch).
Objective-C是开发人员编写此类软件的主要语言。他们可以用纯C编写一些程序,使用c++,或者将其与Objective-C(生成Objective-C+)结合,或者完全用另一种语言编写一些或全部程序,如MacRuby、Java(带有j2objc)或c#(带有MonoTouch)。
Xcode includes the Clang compiler, which turns code written in Objective-C, C, and a few other languages into executable code. Most error messages come from Clang, and Xcode relies heavily on it for search indexing, syntax highlighting, and name completion of Objective-C code.
Xcode包括Clang编译器,它将用Objective-C、C和其他一些语言编写的代码转换为可执行代码。大多数错误消息都来自Clang, Xcode在搜索索引、语法突出显示和Objective-C代码的名称完成方面非常依赖它。
Cocoa and Cocoa Touch are application frameworks. Each one is a suite of many individual frameworks (libraries stored in folders named blahblah.framework), such as:
Cocoa和Cocoa触摸是应用程序框架。每个框架都是许多独立框架的集合(库存储在名为blahblah.framework的文件夹中),例如:
- Foundation (both): General object-oriented utilities, including NSString, NSURL, NSFileManager, etc.
- Core Foundation (both): Mostly the same thing, but different, mainly in having a C-based API rather than Objective-C
- Core Foundation(两者):基本相同,但不同,主要是基于c的API而不是Objective-C
- 基础(两者):一般的面向对象实用程序,包括NSString、NSURL、NSFileManager等
- Application Kit (Mac): Application and windowing framework
- 应用工具包(Mac):应用程序和窗口框架
- UIKit (iOS): Application and windowing framework
- UIKit (iOS):应用程序和窗口框架
- Core Graphics (both): Drawing
- 核心图形(两个):画
- Core Animation (both): Sprite-management and animation framework
- 核心动画(两个):Sprite-management和动画框架。
(and many, many more where they came from, especially on the Mac)
(还有很多人,尤其是在Mac电脑上)
So:
所以:
- You can use a framework besides Cocoa or Cocoa Touch, but you'll have to have some Cocoa/Cocoa Touch code, at some level, in order for your application to talk to the system, receive events, draw, etc. Frameworks that specifically target Mac and/or iOS will include the relevant wrappers for you, at varying levels of quality.
- 您可以使用一个框架除了可可和可可,但是你必须有一些可可/接触代码,在某种程度上,为了使您的应用程序和系统,接收事件,画画,等等。框架专门针对Mac和/或iOS将包括有关包装,在不同等级的品质。
- You can use a language besides Objective-C, but you'll have lots of syntactic awkwardness, as most of Cocoa and Cocoa Touch are designed for Objective-C's unique syntactic features (particularly selectors).
- 除了Objective-C之外,你还可以使用一种语言,但是你会有很多语法上的尴尬,因为大多数的Cocoa和Cocoa Touch都是为Objective-C的独特的句法特性而设计的(特别是选择器)。
- You can use an editor besides Xcode, and you can even use a build system besides Xcode (such as make), but Apple's App Stores expect apps built a particular way (especially with regard to code signing), so unless you're not targeting the App Stores, any other build system has to replicate what Xcode does or risk its users getting rejections.
- 除了Xcode,您可以使用一个编辑器,您甚至可以使用构建系统除了Xcode(比如做),但是苹果的应用程序商店预计应用程序建立了一个特定的方式(特别是关于代码签名),所以除非你不是针对应用程序商店,其他构建系统复制什么Xcode或风险用户被拒绝。
#3
1
A clear mistake is failing to differentiate Xcode from everything else. Xcode is the tool you are using to program in - to edit code, run code, etc. So if you are having trouble with the tool (e.g., the window doesn't show you your code properly, or you're having trouble drawing your interface, etc.), that's an Xcode problem.
一个明显的错误是没有把Xcode和其他东西区分开来。Xcode是你用来编程的工具——用来编辑代码、运行代码等等。所以如果你在使用这个工具时遇到了麻烦(例如,窗口没有正确地显示你的代码,或者你在绘制界面时遇到了麻烦,等等),这就是Xcode的问题。
If you don't understand why your code doesn't work, you're probably having an Objective-C problem or a Cocoa problem. But you won't necessarily know which.
如果您不理解代码为什么不能工作,那么您可能遇到了Objective-C问题或Cocoa问题。但你不一定知道。
-
It's an Objective-C problem if the root of your trouble is that you don't know how the language works (e.g. you don't know what the asterisk is for, or that declaration is not instantiation, or that messages to nil do not error out but don't do anything either).
如果问题的根源在于您不知道语言是如何工作的,那么这就是Objective-C问题(例如,您不知道星号是做什么的,或者声明不是实例化的,或者发送到nil的消息不会出错,但也不会做任何事情)。
-
It's a Cocoa problem if you don't grasp the delegate architecture or how a view controller works.
如果您不掌握委托架构或视图控制器的工作方式,那么这就是一个Cocoa问题。
But my experience of the way people pose questions is that you may be ignorant of which of these you are ignorant of. I don't mean you personally, I mean all of us. This can make it difficult to pose the question properly because you don't know what exactly it is that you don't know — if you did, you'd know it and you probably wouldn't be having a problem (you'd be fixing the problem and on to the next thing).
但我对人们提出问题的方式的经验是,你可能不知道你所不知道的这些。我不是指你,我是指我们所有人。这可能会让你很难恰当地提出问题,因为你不知道你不知道确切的是什么——如果你知道了,你就知道了,你可能就不会有问题了(你会解决问题,接着做下一件事)。