objective-c Cocoa 与 Cocoa Touch - 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2297841/
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
Cocoa versus Cocoa Touch - What is the difference?
提问by Alexandru Luchian
I am learning iOS development in Objective-C, and I have found a lot of code examples.
我正在学习Objective-C中的iOS开发,我发现了很多代码示例。
Some of them, though, say that they are only for Mac OS X (not iOS).
不过,其中一些人说它们仅适用于 Mac OS X(而非 iOS)。
Can someone please explain to me what is the difference between Cocoa and Cocoa Touch (at a library level), so that I know what code will work and what will not work?
有人可以向我解释 Cocoa 和 Cocoa Touch 之间有什么区别(在库级别),以便我知道哪些代码可以工作,哪些不工作?
回答by Jasarien
Cocoa is commonly referred to as the combination of the Foundation and AppKit frameworks, while Cocoa Touch is the combination of the Foundation and UIKit frameworks.
Cocoa 通常被称为 Foundation 和 AppKit 框架的组合,而 Cocoa Touch 是 Foundation 和 UIKit 框架的组合。
Cocoa and Cocoa Touch sit on top of other collections of frameworks to create the API stacks. The other layers are Media, Core Services and Core OS.
Cocoa 和 Cocoa Touch 位于其他框架集合之上以创建 API 堆栈。其他层是媒体、核心服务和核心操作系统。
The main difference between Cocoa and Cocoa touch is that the UI classes and APIs aren't the same as Mac OS X's and macOS's, so instead of NSTextField, you have UITextField. Many of the classes share the same functionality and can be ported quite easily by simply changing the class name, though most will require some more changes, but usually nothing too heavy.
Cocoa 和 Cocoa touch 之间的主要区别在于 UI 类和 API 与 Mac OS X 和 macOS 不同,因此NSTextField您使用的是UITextField. 许多类共享相同的功能并且可以通过简单地更改类名很容易地移植,尽管大多数需要更多的更改,但通常不会太重。
There are also some differences between the Foundation frameworks in Cocoa and Cocoa Touch, most commonly missing classes, for example, Cocoa has NSHostand Cocoa Touch doesn't.
Cocoa 和 Cocoa Touch 中的 Foundation 框架之间也存在一些差异,最常见的是缺少类,例如 Cocoa 有NSHost而 Cocoa Touch 没有。
You will come to know more of the nuances between the two and will soon be able to instinctively know what will work on an iPhone with little/no modification and what will require some work to port between, but it's not that difficult.
您将逐渐了解两者之间的更多细微差别,并且很快就能本能地知道哪些内容无需修改即可在 iPhone 上运行,哪些内容需要在两者之间进行移植,但这并不难。
回答by Sangram Shivankar
Application Framework For
i) Cocoa is the application framework for Mac OS X.
ii) Cocoa Touch is the application framework for iPhone and iPod Touch.
应用程序框架
i) Cocoa 是 Mac OS X 的应用程序框架。ii
) Cocoa Touch 是 iPhone 和 iPod Touch 的应用程序框架。
Frameworks
i) Cocoa: Foundation and AppKit.
ii) Cocoa Touch: Foundation and UIKit
框架
i) Cocoa:Foundation 和 AppKit。
ii) Cocoa Touch:基础和 UIKit
Absence of certain classes
Cocoa has NSHost and Cocoa Touch doesn't
缺少某些类
Cocoa 有 NSHost 而 Cocoa Touch 没有
API
i) Cocoa: All the classes used in Cocoa have the NS prefix Ex: NSTextField
ii) Cocoa Touch: classes used in Cocoa have the UI prefix Ex: UITextField
API
i) Cocoa:Cocoa 中使用的所有类都具有 NS 前缀 Ex: NSTextField
ii) Cocoa Touch:Cocoa 中使用的类具有 UI 前缀 Ex: UITextField
MVC patterns
i) Cocoa: Cocoa has multiple alternative design patterns – in addition to MVC
ii) Cocoa Touch: The iPhone SDK has a reinforced MVC system, which performs better than the default MVC in Cocoa
MVC 模式
i) Cocoa:Cocoa 有多种替代设计模式——除了 MVC
ii) Cocoa Touch:iPhone SDK 有一个增强的 MVC 系统,它比 Cocoa 中的默认 MVC 性能更好
Other Differences
There Are also Differences In App Lifecycle, Sandboxing ,Memory Footprint
其他差异
App Lifecycle、Sandboxing、Memory Footprint 也有差异
Links:
http://teks.co.in/site/blog/cocoa-vs-cocoa-touch-beginners-guide/http://iphonenativeapp.blogspot.in/2011/02/difference-between-cocoacocoa-touch-and.htmlhttps://iphonecodecenter.wordpress.com/tag/difference-between-cocoa-cocoa-touch/
链接:
http: //teks.co.in/site/blog/cocoa-vs-cocoa-touch-beginners-guide/ http://iphonenativeapp.blogspot.in/2011/02/difference-between-cocoacoca-touch- and.html https://iphonecodecenter.wordpress.com/tag/difference-between-cocoa-cocoa-touch/
回答by Joshua Nozzi
The Migrating from Cocoa Touchsection of the iPhone OS Technology Overview provides a good overview of the differences with links to more specific documents for each layer.
该迁移从可可触摸的iPhone OS技术概览部分提供的链接到每一层更具体的文件的差异很好的概述。
The big difference is the UI layer. On the Mac, you have the AppKit framework, on the iPhone, you have UIKit. The smaller differences are in the Foundation framework (linked in the document above).
最大的区别是 UI 层。在 Mac 上,你有 AppKit 框架,在 iPhone 上,你有 UIKit。较小的差异在于 Foundation 框架(在上面的文档中链接)。
回答by onmyway133
In term of importin Swift
在importSwift 方面
import Cocoain Mac OSX application is the same as
import Cocoa在 Mac OSX 应用程序中与
import AppKit
import CoreData
import Foundation
whereas we can't import CocoaTouchin iOS
而我们不能import CocoaTouch在 iOS 中
回答by Sharad Patil
Cocoa versus Cocoa Touch-
Cocoa vs Cocoa Touch-
Cocoa - It is the application framework used for Mac OSX,
Cocoa - 它是用于 Mac OSX 的应用程序框架,
Cocoa Touch - It is the application framework used for iPhone and iPod touch
Cocoa Touch - 它是用于 iPhone 和 iPod touch 的应用程序框架
Cocoa - Foundation + AppKit Framework,
Cocoa Touch - Foundation + UIKIT Framework
Cocoa - 基础 + AppKit 框架,
Cocoa Touch - 基础 + UIKIT 框架
回答by AyAz
1) Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X.
1) Cocoa,包括 Foundation 和 AppKit 框架,用于开发在 OS X 上运行的应用程序。
2) Cocoa Touch, which includes Foundation and UIKit frameworks, is used for developing applications that run on iOS.
2) Cocoa Touch,包括Foundation 和UIKit 框架,用于开发在iOS 上运行的应用程序。

