me icon indicating copy to clipboard operation
me copied to clipboard

学习 MacOS 开发 (Part 8: RunLoop)

Open nonocast opened this issue 2 years ago • 0 comments

Cocoa

官方文档: What Is Cocoa?

Cocoa is an application environment for both the OS X operating system and iOS, the operating system used on Multi-Touch devices such as iPhone, iPad, and iPod touch. It consists of a suite of object-oriented software libraries, a runtime system, and an integrated development environment.

Cocoa in the architecture of OS X

Architecturally, OS X is a series of software layers going from the foundation of Darwin to the various application frameworks and the user experience they support. The intervening layers represent the system software largely (but not entirely) contained in the two major umbrella frameworks, Core Services and Application Services. A component at one layer generally has dependencies on the layer beneath it. Figure 1-1 situates Cocoa in this architectural setting.

在OS X,Cocoa主要有两个关键的Objective-C framework组成:

  • AppKit.AppKit, one of the application frameworks, provides the objects an application displays in its user interface and defines the structure for application behavior, including event handling and drawing.
  • Foundation. This framework, in the Core Services layer, defines the basic behavior of objects, establishes mechanisms for their management, and provides objects for primitive data types, collections, and operating-system services. Foundation is essentially an object-oriented version of the Core Foundation framework.

这里就说明的很清楚, Cocoa提供OC的AppKit和Foundation, Foundation很大一部分是依赖Core Services, 其中就包括Core Foundation, 可以认为Core Foundation是C API,然后Foundation转换成OC API。

Core Foundation. Many classes of the Foundation framework are based on equivalent Core Foundation opaque types. This close relationship is what makes “toll-free bridging”—cast-conversion between compatible Core Foundation and Foundation types—possible. Some of the implementation of Core Foundation, in turn, is based on the BSD part of the Darwin layer.

小结:

  • 如果是使用OC/Swift应该使用Cocoa环境,直接使用Foundation
  • 如果是C, 可以跳开Cocoa Layer直接使用Core Foundation
  • 比如CFRunLoopRef是C API,定义在Core Foundation, NSRunLoop就是对CFRunLoopRef的OC转换, 当然同时也提供增值服务
  • Cocoa以NS作为前缀,表示NextStep, CF则是Core Foundation的缩写

参考阅读

nonocast avatar Apr 29 '22 08:04 nonocast