Introduction to Cocoa

0

Category:

Cocoa provides a rich layer of functionality on which you can build applications. Its comprehensive object-oriented API complements a large number of technologies that Mac OS X provides. Some of these technologies are inherited from the NeXTSTEP operating system. Others are based on the BSD Unix heritage of Mac OS X's core. Still others come from the original Macintosh environment and have been updated to work with a modern operating system. In many cases, you take advantage of these underlying technologies transparently, and you get the use of them essentially "for free." In some cases, you might use these technologies directly, but because of the way Cocoa is structured, they are a simple and direct API call away.

Mac OS X provides five principal application environments:
Carbon

A set of procedural APIs for working with Mac OS X. These interfaces were initially derived from the earlier Mac OS Toolbox APIs and modified to work with Mac OS X's protected memory environment and preemptive task scheduling. As a transitional API, Carbon gives developers a clear way to migrate legacy
Cocoa

A set of object-oriented APIs derived from NeXT's operating-system technologies that take advantage of many features from Carbon. Programming with the Cocoa API is the focus of this book. Many applications that ship with Mac OS X, such as Mail and Stickies, are written in Cocoa. In addition, many of Apple's latest applications, such as iPhoto, iChat, and iDVD2, are built on top of Cocoa.

Java

A robust and fast virtual-machine environment for running applications developed using the Java Development Kit. Java applications are typically very portable and can run unchanged, without recompilation, on many different computing environments.

BSD Unix

The BSD layer of Mac OS X that provides a rich, robust, and mature set of tools and system calls. The standard BSD tools, utilities, APIs, and functions are available to applications. A command-line environment also exists as part of this layer.

Classic

The compatibility environment in which the system runs applications originally written for Mac OS 8 or Mac OS 9 that have not been updated to take full advantage of Mac OS X. Classic is essentially a modified version of Mac OS 9 running inside a process that has special hooks into other parts of the operating system. Over time, Classic is becoming less interesting as more applications are
ported to run negatively in Mac OS X.





 each of Mac OS X's application environments relies upon functionality provided by deeper layers of the operating system. This functionality is roughly broken into two major sections: Core Foundation, which provides a common set of application and core services to the Cocoa, Carbon, and Java frameworks, and the kernel environment, which is the underlying Unix-based core of the operating system.

[1]
Contrary to what you may have heard elsewhere, Carbon is not doomed to fade away over time.
This erroneous opinion seems to be caused by a misinterpretation of the word "transitional" to
mean that the API itself will be going away, rather than meaning it is the API to use to transition
older applications. Moving forward, it will remain one of the core development environments for
Mac OS X. In fact, Apple engineers are striving to enable better integration between Carbon and
Cocoa.


1.2 Cocoa Defined
Cocoa is an advanced object-oriented framework for building applications that run on Apple's Mac OS X. It is an integrated set of shared object libraries, a runtime system, and a development environment. Cocoa provides most of the infrastructure that graphical user applications typically need and insulates those applications from the internal workings of the core operating system.

Think of Cocoa as a layer of objects acting as both mediator and facilitator between programs that you build and the operating system. These objects span the spectrum from simple wrappers for basic types, such as strings and arrays, to complex functionality, such as distributed computing and advanced imaging. They are designed to make it easy to create a graphical user interface (GUI) application and are based on a sophisticated infrastructure that simplifies the programming task.

Cocoa-based applications are not just limited to using the features in the Cocoa frameworks. They can also use all of the functionality of the other frameworks that are part of Mac OS X, such as Quartz, QuickTime, OpenGL, ColorSync, and many others. And since Mac OS X is built atop Darwin, a solid BSD-based system,[2] Cocoa-based applications can use all of the core Unix system functions and get as close to the underlying filesystem, network services, and devices as they need to.

The History of Cocoa
Cocoa has actually been around a long time-almost as long as the Macintosh itself. That is because it is, to a large extent, based on OpenStep, which was introduced to the world as NeXTSTEP in 1987, along with the elegant NeXT cube. At the time, the goal of NeXTSTEP was to, as only Steve Jobs could say, "create the next insanely great thing." It evolved through many releases, was adopted by many companies as their development and deployment environment of choice, and received glowing reviews in the press. It was, and continues to be, solid technology based on a design that was years ahead of anything else in the market.

NeXTSTEP was built on top of BSD Unix from UC Berkeley and the Mach microkernel from Carnegie-Mellon University. It utilized Display PostScript from Adobe - allowing the same code, using the PostScript page description language - to display documents on screen and to print to paper. NeXTSTEP came with a set of libraries, called "frameworks," and tools to enable programmers to build applications using the Objective-C language.

In 1993 NeXT exited the hardware business to concentrate on software. NeXTSTEP was ported to the Intel x86 architecture and released. Other ports were performed for the SPARC, Alpha, and PA-RISC architectures. Later, the frameworks and tools were revised to run on other operating systems, such as Windows and Solaris. These revised frameworks became known as OpenStep.

Fast forward to 1996. Apple had been working unsuccessfully on a next-generation operating system, known as Copland, to replace the venerable Mac OS 7. Their efforts were running amok and they decided to look outside for the foundation of the new OS. The leading contender seemed to be BeOS, but in a surprise move, Apple acquired NeXT, citing its strengths in development software and operating environments for both the enterprise and Internet markets. As part of this merger, Apple embarked on the development of Rhapsody, a development of the NeXTSTEP operating system fused with
the classic Mac OS. Over the next five years, Rhapsody evolved into what was released as Mac OS X 10.0. As part of that evolution, OpenStep became Cocoa.

Mac OS X remains very much a Unix system; the Unix side of Mac OS X is just hidden
from users unless they really want to use it. Its full power, however, is available to you, the
programmer, to utilize. Not only can you take advantage of the power, you can actually
look under the hood and see how it all works. The source code to the underpinnings of Mac
OS X can be found as part of Apple's Darwin initiative (http://www.developer.apple.com/ darwin).

1.2.2 Cocoa's Feature Set
At its foundation, Cocoa provides basic types such as strings and arrays, as well as basic functions such as byte swapping, parsing, and exception handling. Cocoa also provides utilities for memory management, utilities for archiving and serializing objects, and access to kernel entities and services such as tasks, ports, run loops, timers, threads, and locks.
 Internationalization and localization

Cocoa's well-designed internationalization architecture allows applications to be localized easily into multiple languages. Cocoa keeps the user-interface elements separate from the executable, enabling multiple localizations to be bundled with an application. The underlying technology is the same that is used by Mac OS X to ship a single build of the OS with many localizations.

Text and fonts

Cocoa offers a powerful set of text services that can be readily adapted by text-intensive applications. These services include kerning, ligatures, tab formatting, and rulers, and they can support text buffers as large as the virtual memory space. The text system also supports embedded graphics and other inline attachments.

Cocoa supports a variety of font formats, including the venerable Adobe PostScript (including Types 1, 3, and 42), the TrueType format defined by Apple in the late 1980s and adopted by Microsoft in Windows 3.1, and the new OpenType format, which merges the capabilities of both PostScript and TrueType.

Exported application services

Cocoa applications can make functionality available to other applications, as well as to end users, through two mechanisms: scripting with AppleScript and via Services.

AppleScript enables users to control applications directly on their system, including the operating system itself. Scripts allow even relatively unskilled users to automate common tasks and afford skilled scripters the ability to combine multiple applications to perform more complex tasks. For example, a script that executes when a user logs in could open the user's mail, look for a daily news summary message, and open the URLs from the summary in separate web-browser windows.
Scripts have access to the entire Mac OS X environment, as well as other applications. For example, a script can launch the Terminal application, issue a command to list the running processes, and use the output for some other purpose.

Services, available as a submenu item of the application menu, allow users to use functionality of an application whenever they need to. For example, you can highlight some text in an application and choose the "Make New Sticky Note" service. This will launch the Stickies application (/Applications), create a new Sticky, and put the text of your selection into it. This functionality is not limited to
text; it can work with any data type.

Component technologies

One of the key advantages of Cocoa as a development environment is its capability to develop programs quickly and easily by assembling reusable components. With the proper programming tools and a little work, you can build Cocoa components that can be packaged and distributed for use by others. End-user applications are the most familiar use of this component technology in action. Other examples
include the following:

.
Bundles containing executable code and associated resources that programs
can load dynamically .
Frameworks that other developers can use to create programs
.
Palettes containing custom user-interface objects that other developers can drag and drop into their own user interfaces
Cocoa's component architecture allows you to create and distribute extensions and plug-ins easily for applications. In addition, this component architecture enables Distributed Objects, a distributed computing model that takes unique advantage of Cocoa's abilities. 

Comments (0)

Post a Comment

Copyright © 2009 virtualinfocom All rights reserved. Theme by Games. | animation Ani2Pix.