CocoaAndCocoaEnvironment Introduction is the content of this article.Mac OS XOn the operating system,CocoaLike Carbon and Java, it is an application environment. It consists of an object-oriented software library and a runtime environment. Its integrated development environment is the same as other application environments. This chapter will expand and describe Based on this definition.CocoaGoals, capabilities, and physical forms.
Cocoa Environment
The Cocoa application is gradually becoming the application standard for Mac OS X. IPhoto, Safari, and Mail are all Cocoa applications. These applications are well received for their smart design, rich functionality, and exciting user interfaces. However, it is not obvious for general users to compare with the typical development cycle): How fast the process from the design phase to the final deployment of these programs is. As an application development environment, what makes Cocoa a practical and even mandatory alternative to Carbon.
Like all application environments, Cocoa includes two aspects: runtime environment and development. In terms of the runtime environment, the Cocoa application presents the Aqua user interface and is closely integrated with other visual components of the operating system, including the Finder, Dock, and other applications based on all environments. Cocoa seamlessly serves as a part of the user experience and delivers excellent performance in the runtime environment.
However, programmers are more interested in development. Cocoa is an object-oriented software component-class-integrated suite that allows developers to quickly create strong and fully functional Mac OS X applications. These classes are reusable and disposable software blocks that developers can use directly or expand based on their specific needs. From user interface objects to Bonjour networks, almost every imaginary development requirement has a corresponding Cocoa class, you can easily derive subclass from an existing class.
Among various object-oriented development environments, Cocoa has the most famous lineage. Since its launch as NeXTSTEP in 1989, people have been refining and testing it. For more information, see "a little history ). Its elegant and powerful design perfectly fits all types of fast software development: not only for developing applications, but also for developing command line tools, plug-ins, and different types of packages. Cocoa provides a lot of behavior and appearance for your application for "free", so that you can spend more time on featured features for detailed information about the features provided by Cocoa, see "Features of the Cocoa application ).
You can use multiple programming languages when developing Cocoa software. The basic language is Objective-C. Objective-C has its own Cocoa runtime environment and is a superset of ansi c, which is derived from Smalltalk in terms of ansi c syntax and semantics, it supports object-oriented programming. The new rules are simple and easy to learn and use. Since Objective-C is based on ansi c, you can freely mix C Code directly with Objective-C code. In addition, your code can call all functions defined in non-Cocoa programming interfaces, such as Carbon and BSD. You can even mix C ++ code into Cocoa code and connect them to the same execution file. Finally, Cocoa supports Java. Cocoa defines a parallel Java class library and implements a bridge mechanism to map Java interfaces to Objective-C implementations. Cocoa's Java support allows you to mix local Java objects and Cocoa objects for use under certain restrictions)
Important: Cocoa-Java is a learning environment for developers familiar with the Java language. We do not recommend it for product development. Objective-C APIs are constantly evolving, while Cocoa-Java APIs are not maintained in parallel.
You can even use PyObjC, the Python/Objective-C bridge, to program Cocoa. Based on PyObjC, you can use Python to write Cocoa programs. Python is an explanatory, interactive, and object-oriented programming language. PyObjC enables a Python object to send messages to an Objective-C object, just like a Python object. It also enables an Objective-C object to send messages to a Python object. For more information, see "Developing PyObjC-based Cocoa applications using Python", which is on the Apple Developer Connection website of the Apple Developer alliance.
The core Cocoa class library is encapsulated in two frameworks: Foundation and Application Kit. Like all frameworks, these two frameworks not only contain dynamic shared libraries and sometimes several compatible versions), but also include header files, API documents, and related resources. The separation of Application Kit and Foundation framework reflects that Cocoa programming interfaces are divided into graphic user interfaces and non-graphic interfaces. These two frameworks are necessary for the Cocoa project where the final product is the application. There are also a few small frameworks that use Cocoa programming interfaces, such as Screen Saver Screen protection and Address Book) released together with Mac OS X. Over time, more frameworks will be added to the operating system. For more information, see the "Cocoa framework" section.
Location of Cocoa in Mac OS X
Figure 1-1 shows a simplified Mac OS X system architecture diagram:
Figure 1-1 Mac OS X-architecture-Simplified View
This diagram is for a simple purpose: to explicitly identify the main components and dependencies of Mac OS X for developers who are not familiar with the apple platform. For simplicity, some important details are omitted in the figure and the other parts are blurred. These details constitute an important part of the block diagram, showing the relationship between Cocoa and other parts of Mac OS X.
Figure 1-2 shows the location of Cocoa more accurately at the architecture level. This diagram shows Mac OS X as a series of software layers, from basic Darwin of the system to various application environments. The middle layer represents system software included in Core Services) and Application Services. In this diagram, a layer usually depends on other layers.
Figure 1-2 Location of Cocoa in Mac OS X Architecture
In some respects, this diagram is similar to the previous one. For example, Quartz, the system component responsible for rendering the Aqua user interface, is implemented in the Core Graphics framework. It is part of the Application Services layer. The basic part of the architecture stack is Darwin, includingCocoaIncludingMac OS XEach part is ultimately dependent on Darwin.
However, if you further look at one or more of the umbrella frameworks) Cocoa subclasses or specific sub-frameworks, you will find that Cocoa or other components of Mac OS X have specific dependencies, or you can use your own interfaces to provide external basic technologies. Figure 1-3 shows the preceding dependency and external interfaces.
Note: although Cocoa depends on a specific framework, it is not just "sitting" on these frameworks. In some cases, Cocoa is equivalent to other frameworks such as Carbon, and can even implement tasks that cannot be implemented by other peer frameworks. Cocoa is not just an object-oriented encapsulation layer above the basic technology.
Figure 1-3 further investigate the Cocoa architecture-some major Dependencies
Apple has carefully designed Cocoa to make the Cocoa programming interface a basic technology access channel that is usually required by applications. However, if you need some capabilities that cannot be found in the Cocoa interface, or you need to perform more detailed control over the application, you can also directly use the underlying framework Core Graphics as an important example. by calling the framework or OpenGL functions, your code can draw images that are more complex and slightly different than the Cocoa method ). Fortunately, using these low-level frameworks is not a problem, because the vast majority of programming interfaces dependent on the Framework are written in ansi c, and Objective-C is its superset.
Note: The purpose of the Architecture Overview section is not to listCocoaWhich interfaces orMac OS XWhat are the dependencies of other parts. On the contrary, the overview section is just the most interesting part to consider. It aims to give you a basic idea about the framework architecture.
Core Foundation, Carbon, Core Graphics (Quartz), Launch Services, and Print Core (Print subsystem ). The details are as follows:
Core Foundation. Many classes of the Foundation framework are based on the encapsulation type corresponding to the Core Foundation. This closeness between them makes "Free bridging" technology-that is, implementing type conversion between compatible Core Foundation and Foundation types-possible. Some Core foundations are implemented based on BSD of the Darwin layer.
Carbon. Cocoa uses some Services provided by Carbon because some Carbon frameworks are positioned as system-level Services at the Core Services and Application Services layers. As an example, Carbon Core is a particularly important component in these frameworks. Cocoa uses the File Manager component provided by it to convert the representation of different File systems.
Core Graphics. Cocoa plotting and image processing classes are quite natural and close) based on the Core Graphics framework, it implements Quartz and window server components.
Launch Services. The NSWorkspace class provides the potential capabilities of Launch Services. Cocoa also uses the Application Registration feature provided by Launch Services to obtain icons associated with applications and documents.
Print Core. Cocoa printing class is an object-oriented interface of the Printing Subsystem.
In addition, Cocoa uses the Text Encoding Converter in the Carbon environment) Service to process some string Encoding conversions. There are also someCocoaThe method provides some functions of the I/O Kit framework, QuickDraw (QD) framework, Apple Event (AE) framework, and ATS framework, it is used for power management, QuickDraw plotting, Apple Event processing, and font support.
Further reading:Mac OS XThe technology overview book provides related frameworks, services, technologies, andMac OS XOverview of other components. The Apple Man-Machine Interface Guide focuses on the appearance and behavior of the Aqua Man-machine interface.
Summary: AboutCocoaAndCocoaThe Environment Introduction tutorial is complete. I hope this article will help you!