Cocoa (API)
Encyclopedia
Cocoa is Apple's native object-oriented application programming interface
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 (API) for the Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 and—along with the Cocoa Touch
Cocoa Touch
Cocoa Touch is an API for building software programs to run on the iPhone, iPod Touch, and iPad from Apple Inc.Cocoa Touch provides an abstraction layer of iOS, the operating system for the iPhone, iPod Touch, and iPad. Cocoa Touch is based on the Mac OS X Cocoa API toolset and, like it, is...

 extension for gesture recognition
Gesture recognition
Gesture recognition is a topic in computer science and language technology with the goal of interpreting human gestures via mathematical algorithms. Gestures can originate from any bodily motion or state but commonly originate from the face or hand. Current focuses in the field include emotion...

 and animation
Animation
Animation is the rapid display of a sequence of images of 2-D or 3-D artwork or model positions in order to create an illusion of movement. The effect is an optical illusion of motion due to the phenomenon of persistence of vision, and can be created and demonstrated in several ways...

—for applications for the iOS operating system, used on Apple devices such as the iPhone
IPhone
The iPhone is a line of Internet and multimedia-enabled smartphones marketed by Apple Inc. The first iPhone was unveiled by Steve Jobs, then CEO of Apple, on January 9, 2007, and released on June 29, 2007...

, the iPod Touch
IPod Touch
The iPod Touch is a portable media player, personal digital assistant, handheld game console, and Wi-Fi mobile device designed and marketed by Apple Inc. The iPod Touch adds the multi-touch graphical user interface to the iPod line...

, and the iPad
IPad
The iPad is a line of tablet computers designed, developed and marketed by Apple Inc., primarily as a platform for audio-visual media including books, periodicals, movies, music, games, and web content. The iPad was introduced on January 27, 2010 by Apple's then-CEO Steve Jobs. Its size and...

.

Cocoa applications are typically developed using the development tools provided by Apple, specifically Xcode
Xcode
Xcode is a suite of tools, developed by Apple, for developing software for Mac OS X and iOS. Xcode 4.2, the latest major version, is available on the Mac App Store for free for Mac OS X 10.7 , and on the Apple Developer Connection website for free to registered developers Xcode is a suite of tools,...

 (formerly Project Builder
Project Builder
Project Builder was an integrated development environment originally developed by NeXT for the NeXTSTEP operating system. It was rewritten and informally dubbed PBX while distributed by Apple Computer for software development on Mac OS X computer systems prior to Mac OS X v10.3...

) and Interface Builder
Interface Builder
Interface Builder is a software development application for Apple's Mac OS X operating system. It is part of Xcode , the Apple Developer Connection developer's toolset. Interface Builder allows Cocoa and Carbon developers to create interfaces for applications using a graphical user...

, using the Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...

 language. However, the Cocoa programming environment can be accessed using other tools, such as Clozure CL
Clozure CL
Clozure CL is a Common Lisp implementation. It implements the full ANSI Common Lisp standard with several extensions...

, LispWorks
LispWorks
LispWorks is a commercial implementation and IDE for the Common Lisp programming language. The software runs on Microsoft Windows, Mac OS X , Linux, FreeBSD, Solaris and HP UX....

, Object Pascal
Object Pascal
Object Pascal refers to a branch of object-oriented derivatives of Pascal, mostly known as the primary programming language of Embarcadero Delphi.-Early history at Apple:...

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

, and AppleScript
AppleScript
AppleScript is a scripting language created by Apple Inc. and built into Macintosh operating systems since System 7. The term "AppleScript" may refer to the scripting system itself, or to particular scripts that are written in the AppleScript language....

 with the aid of bridging mechanisms such as PasCocoa
PasCocoa
PasCocoa is an open source compiler for projects written in Pascal and Object Pascal. PasCocoa works by extending the Pascal programming language so that it can directly interface with code written in Objective-C using new language constructs....

, PyObjC
PyObjC
PyObjC is a bidirectional bridge between Python and Objective-C. It allows Python scripts to use and extend existing Objective-C class libraries....

, CamelBones
CamelBones
CamelBones is a programming framework that allows one to use Mac OS X's Cocoa API through Perl. Its main author and maintainer was Sherm Pendley, before he died in 2011....

 and RubyCocoa
RubyCocoa
RubyCocoa is a Mac OS X framework that provides a bridge between the Ruby and the Objective-C programming languages, allowing the user to manipulate Objective-C objects from Ruby, and vice-versa. It makes it possible to write a Cocoa application completely in Ruby as well as to write an application...

. An implementation of the Ruby language, called MacRuby
MacRuby
MacRuby is an implementation of the Ruby language that runs on the Objective-C runtime and CoreFoundation framework under development by Apple Inc. which "is supposed to replace RubyCocoa". It is based on Ruby 1.9 and uses the high performance Low Level Virtual Machine compiler infrastructure...

, which does away with the requirement for a bridging mechanism, is under development by Apple, while Nu
Nu (programming language)
Nu is an interpreted object-oriented programming language, with a Lisp-like syntax, created by Tim Burks as an alternative scripting language to program Mac OS X through its Cocoa application programming interface...

 is a Lisp-like language which can be used with Cocoa without a bridge. It is also possible to write Objective-C Cocoa programs in a simple text editor
Text editor
A text editor is a type of program used for editing plain text files.Text editors are often provided with operating systems or software development packages, and can be used to change configuration files and programming language source code....

 and build it manually with GCC
GNU Compiler Collection
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...

 or clang
Clang
Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages. It uses the Low Level Virtual Machine as its back end, and Clang has been part of LLVM releases since LLVM 2.6....

 from the command line or from a makefile.

For end-users, Cocoa application
Application software
Application software, also known as an application or an "app", is computer software designed to help the user to perform specific tasks. Examples include enterprise software, accounting software, office suites, graphics software and media players. Many application programs deal principally with...

s are considered to be those written using the Cocoa programming environment. Such applications usually have a distinctive feel, since the Cocoa programming environment automates many aspects of an application to comply with Apple's human interface guidelines
Human Interface Guidelines
Human interface guidelines are software development documents which offer application developers a set of recommendations. Their aim is to improve the experience for the users by making application interfaces more intuitive, learnable, and consistent. Most guides limit themselves to defining a...

.

Cocoa history

Cocoa continues the lineage of several frameworks (primarily the App Kit and Foundation Kit) from the NeXTSTEP
NEXTSTEP
NeXTSTEP was the object-oriented, multitasking operating system developed by NeXT Computer to run on its range of proprietary workstation computers, such as the NeXTcube...

 and OpenStep
OpenStep
OpenStep was an object-oriented application programming interface specification for an object-oriented operating system that used a non-NeXTSTEP operating system as its core, principally developed by NeXT with Sun Microsystems. OPENSTEP was a specific implementation of the OpenStep API developed...

 programming environments developed by NeXT
NeXT
Next, Inc. was an American computer company headquartered in Redwood City, California, that developed and manufactured a series of computer workstations intended for the higher education and business markets...

 in the 1980s and 1990s. Apple acquired NeXT in December 1996, and subsequently went to work on the Rhapsody operating system that was supposed to be the direct successor of OpenStep. It was to have had an emulation base for Mac OS
Mac OS
Mac OS is a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems. The Macintosh user experience is credited with popularizing the graphical user interface...

 applications, called Blue Box. The OpenStep base of libraries and binary support was termed Yellow Box. Rhapsody evolved into Mac OS X, and the Yellow Box became Cocoa. As a result, Cocoa classes begin with the acronym "NS" (standing either for the NeXT-Sun creation of OpenStep, or for the original proprietary term for the OpenStep framework, NeXTSTEP): NSString, NSArray, etc.

Much of the work that went into developing OpenStep was applied to the development of Mac OS X, Cocoa being the most visible part. There are, however, some differences. For example, NeXTSTEP and OpenStep used Display PostScript
Display PostScript
Display PostScript is an on-screen display system. As the name implies, DPS uses the PostScript imaging model and language to generate on-screen graphics...

 for on-screen display of text and graphics, while Cocoa depends on Apple's Quartz
Quartz (graphics layer)
Quartz specifically refers to a pair of Mac OS X technologies, each part of the Core Graphics framework: Quartz 2D and Quartz Compositor. It includes both a 2D renderer in Core Graphics and the composition engine that sends instructions to the graphics card...

 (which uses the PDF
Portable Document Format
Portable Document Format is an open standard for document exchange. This file format, created by Adobe Systems in 1993, is used for representing documents in a manner independent of application software, hardware, and operating systems....

 imaging model, but not its underlying technology). Cocoa also has a level of Internet support, including the NSURL and WebKit HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 classes, and others. While under OpenStep there was only rudimentary support for managed network connections through NSFileHandle classes and Berkeley sockets
Berkeley sockets
The Berkeley sockets application programming interface comprises a library for developing applications in the C programming language that perform inter-process communication, most commonly for communications across a computer network....

.

Before its current use, the "Cocoa" trademark was the name of an application that helped children create multimedia projects. Originally known as KidSim, it is licensed to a third party and marketed as Stagecast Creator
Stagecast Creator
Stagecast Creator is a visual programming language intended for use in teaching programming to children. It is based on the programming by demonstration concept, where rules are created by giving examples of what actions should take place in a given situation...

. The program was discontinued in one of the rationalizations
Rationalization (economics)
In economics, rationalization is an attempt to change a pre-existing ad hoc workflow into one that is based on a set of published rules. There is a tendency in modern times to quantify experience, knowledge, and work. Means-end rationality is used to precisely calculate that which is necessary to...

 that followed Steve Jobs
Steve Jobs
Steven Paul Jobs was an American businessman and inventor widely recognized as a charismatic pioneer of the personal computer revolution. He was co-founder, chairman, and chief executive officer of Apple Inc...

' return to Apple. The name was re-used to avoid the delay while registering a new trademark
Trademark
A trademark, trade mark, or trade-mark is a distinctive sign or indicator used by an individual, business organization, or other legal entity to identify that the products or services to consumers with which the trademark appears originate from a unique source, and to distinguish its products or...

, with Stagecast agreeing to market the older Cocoa under a new name.

Memory management

One feature of the Cocoa environment is its facility for managing dynamically allocated memory. Cocoa's NSObject class, from which most classes, both vendor and user, are derived, implements a reference counting
Reference counting
In computer science, reference counting is a technique of storing the number of references, pointers, or handles to a resource such as an object, block of memory, disk space or other resource...

 scheme for memory management. Objects derived from the NSObject root class respond to a retain and a release message and keep a retain count which can be queried by sending a retainCount message. A newly allocated object created with alloc or copy has a retain count of one. Sending that object a retain message increments the retain count, while sending it a release message decrements the retain count. When an object's retain count reaches zero, it is deallocated similar to a C++ destructor. dealloc is not guaranteed to be invoked.

Starting with Objective-C 2.0, the Objective-C runtime implements an optional garbage collector. In this model, the runtime turns Cocoa reference counting
Reference counting
In computer science, reference counting is a technique of storing the number of references, pointers, or handles to a resource such as an object, block of memory, disk space or other resource...

 operations such as "retain" and "release" into no-ops. The garbage collector does not exist on the iOS
IOS
iOS is an operating system for iPad, iPhone, iPod Touch, and Apple TV.IOS may also refer to:-Companies and organisations:* Illinois Ornithological Society, American state-based bird club...

 implementation of Objective-C 2.0. Garbage Collection in Objective-C runs on a low-priority background thread, and can halt on Cocoa's user events, with the intention of keeping the user experience responsive.

In 2011, the LLVM compiler introduced ARC (automated reference counting), which replaces the conventional garbage collector by performing static analysis of Objective-C source code and inserting retain and release messages as necessary.

Main frameworks

Cocoa consists primarily of two Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...

 object libraries called framework
Application framework
In computer programming, an application framework consists of a software framework used by software developers to implement the standard structure of an application for a specific development environment ....

s
. Frameworks are functionally similar to shared libraries
Library (computer science)
In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications....

, a compiled object that can be dynamically loaded into a program's address space at runtime, but frameworks add associated resources, header files, and documentation. The Cocoa frameworks are implemented as a type of application bundle, containing the aforementioned items in standard locations.
  • Foundation Kit
    Foundation Kit
    The Foundation Kit, or just Foundation for short, is an Objective-C framework in the OpenStep specification. It provides basic classes such as wrapper classes and data structure classes. This framework uses the prefix NS .-NSObject:...

    , or more commonly simply Foundation, first appeared in OpenStep. On Mac OS X, it is based on Core Foundation
    Core Foundation
    Core Foundation is a C application programming interface in Mac OS X & iOS, and is a mix of low-level routines and wrapper functions...

    . Foundation is a generic object-oriented library providing string
    String (computer science)
    In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....

     and value manipulation, containers
    Container (data structure)
    In computer science, a container is a class, a data structure, or an abstract data type whose instances are collections of other objects. In other words; they are used for storing objects in an organized way following specific access rules...

     and iteration
    Iteration
    Iteration means the act of repeating a process usually with the aim of approaching a desired goal or target or result. Each repetition of the process is also called an "iteration," and the results of one iteration are used as the starting point for the next iteration.-Mathematics:Iteration in...

    , distributed computing
    Distributed computing
    Distributed computing is a field of computer science that studies distributed systems. A distributed system consists of multiple autonomous computers that communicate through a computer network. The computers interact with each other in order to achieve a common goal...

    , run loop
    Event loop
    In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program...

    s, and other functions that are not directly tied to the graphical user interface. The "NS" prefix, used for all classes and constant
    Constant (programming)
    In computer programming, a constant is an identifier whose associated value cannot typically be altered by the program during its execution...

    s in the framework, comes from Cocoa's OPENSTEP heritage, which was jointly developed by NeXT and Sun
    Sun
    The Sun is the star at the center of the Solar System. It is almost perfectly spherical and consists of hot plasma interwoven with magnetic fields...

    .
  • Application Kit
    Application Kit
    The Application Kit is a collection of classes within the OpenStep specification and provided by such operating systems as OPENSTEP, GNUstep, and Mac OS X under Cocoa, providing classes oriented around graphical user interface capabilities...

    or AppKit is directly descended from the original NeXTSTEP Application Kit. It contains code with which programs can create and interact with graphical user interface
    Graphical user interface
    In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

    s. AppKit is built on top of Foundation, and uses the same "NS" prefix.


A key part of the Cocoa architecture is its comprehensive views model. This is organized along conventional lines for an application framework, but is based on the PDF
Portable Document Format
Portable Document Format is an open standard for document exchange. This file format, created by Adobe Systems in 1993, is used for representing documents in a manner independent of application software, hardware, and operating systems....

 drawing model provided by Quartz
Quartz (graphics layer)
Quartz specifically refers to a pair of Mac OS X technologies, each part of the Core Graphics framework: Quartz 2D and Quartz Compositor. It includes both a 2D renderer in Core Graphics and the composition engine that sends instructions to the graphics card...

. This allows creation of custom drawing content using PostScript
PostScript
PostScript is a dynamically typed concatenative programming language created by John Warnock and Charles Geschke in 1982. It is best known for its use as a page description language in the electronic and desktop publishing areas. Adobe PostScript 3 is also the worldwide printing and imaging...

-like drawing commands, which also allows automatic printer support and so forth. Since the Cocoa framework manages all the clipping, scrolling, scaling and other chores of drawing graphics, the programmer is freed from implementing basic infrastructure and can concentrate only on the unique aspects of an application's content.

Model-view-controller

The Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

 teams at Xerox PARC
Xerox PARC
PARC , formerly Xerox PARC, is a research and co-development company in Palo Alto, California, with a distinguished reputation for its contributions to information technology and hardware systems....

 eventually settled on a design philosophy that led to easy development and high code reuse. Known as "model-view-controller
Model-view-controller
Model–view–controller is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" from the user interface , permitting independent development, testing and maintenance of each .Model View Controller...

" (MVC), the concept breaks an application into three sets of interacting object classes.
  • Model classes represent raw data, such as documents, settings, files, or objects in memory.
  • Views are, as the name implies, visual representations of the data in the model.
  • Controller classes contain logic which links the models to their views, and maintains state to keep them synchronized.


Cocoa's design is a strict application of MVC principles. Under OpenStep, most of the classes provided were either high-level View classes (in AppKit) or one of a number of relatively low-level model classes like NSString. Compared to similar MVC systems, OpenStep lacked a strong model layer. There was no stock class which represented a "document," for instance. During the transition to Cocoa, the model layer was expanded greatly, introducing a number of pre-rolled classes to provide functionality common to desktop applications.

In Mac OS X 10.3, Apple introduced the NSController family of classes, which provide predefined behavior for the controller layer. These classes are considered part of the Cocoa Bindings system, which also makes extensive use of protocols such as Key-Value Observing and Key-Value Binding. The term 'binding' refers to a relationship between two objects, often between a view and a controller. Bindings allow the developer to focus more on declarative relationships rather than orchestrating fine-grained behavior.

With the arrival of Mac OS X 10.4, Apple extended this foundation further by introducing the Core Data
Core Data
Core Data is part of the Cocoa API in Mac OS X first introduced with Mac OS X 10.4 Tiger and for iOS with iPhone SDK 3.0. It allows data organised by the relational entity-attribute model to be serialised into XML, binary, or SQLite stores. The data can be manipulated using higher level objects...

 framework, which standardizes change tracking and persistence in the model layer. In effect, the framework greatly simplifies the process of making changes to application data, undoing changes (if necessary), saving data to disk, and reading it back in.

By providing framework support for all three MVC layers, Apple's goal is to reduce the amount of boilerplate or "glue" code that developers have to write, freeing up resources to spend time on application-specific features.

Late binding

In most object-oriented languages, calls to methods are represented physically by a pointer to the code in memory. This restricts the design of an application since specific "command handling" classes are required, usually organized according to the chain-of-responsibility design pattern
Chain-of-responsibility pattern
In Object Oriented Design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains a set of logic that describes the types of command objects that it can handle, and how to pass off those...

. While Cocoa retains this approach for the most part, Objective-C's late binding opens up more flexibility.

Under Objective-C, methods are represented by a selector, a string describing the method to be called. When a message is sent, the selector is sent into the ObjC runtime, matched against a list of available methods, and the method's implementation is called. Since the selector is text data, this allows it to be saved to a file, transmitted over a network or between processes, or manipulated in other ways. The implementation of the method is looked up at runtime, not compile time. There is a small performance penalty for this, but late binding allows the same selector to reference different implementations.

By a similar token, Cocoa provides a pervasive data manipulation method called key-value coding (KVC). This permits a piece of data or property of an object to be looked up or changed at runtime by name — the property name acts as a key to the value itself. In traditional languages, this late binding is not possible. KVC leads to great design flexibility — an object's type does not need to be known, yet any property of that object can be discovered using KVC. In addition, by extending this system using something Cocoa calls Key-Value Observing (KVO), automatic support for Undo/Redo is provided.

Late static binding is a variant of binding somewhere between static and dynamic binding. The binding of names before the program is run is called static ("early"); bindings performed as the program runs are dynamic ("late" or "virtual").

Rich objects

One of the most useful features of Cocoa is the powerful "base objects" the system supplies. As an example, consider the Foundation classes NSString and NSAttributedString, which provide Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

 string
String (computer science)
In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....

s, and the NSText system in AppKit, which allows the programmer to place string objects in the GUI.

NSText and its related classes are used to display and edit strings. The collection of objects involved permit an application to implement anything from a simple single-line text entry field to a complete multi-page, multi-column text layout schema, with full professional typography
Typography
Typography is the art and technique of arranging type in order to make language visible. The arrangement of type involves the selection of typefaces, point size, line length, leading , adjusting the spaces between groups of letters and adjusting the space between pairs of letters...

 features such as kerning
Kerning
In typography, kerning is the process of adjusting the spacing between characters in a proportional font, usually to achieve a visually pleasing result. Kerning is the adjustment of the space between individual letter forms vs. tracking which is the uniform adjustment of spacing applied over a...

, ligature
Ligature (typography)
In writing and typography, a ligature occurs where two or more graphemes are joined as a single glyph. Ligatures usually replace consecutive characters sharing common components and are part of a more general class of glyphs called "contextual forms", where the specific shape of a letter depends on...

s, running text around arbitrary shape
Shape
The shape of an object located in some space is a geometrical description of the part of that space occupied by the object, as determined by its external boundary – abstracting from location and orientation in space, size, and other properties such as colour, content, and material...

s, rotation
Rotation
A rotation is a circular movement of an object around a center of rotation. A three-dimensional object rotates always around an imaginary line called a rotation axis. If the axis is within the body, and passes through its center of mass the body is said to rotate upon itself, or spin. A rotation...

, full Unicode support and anti-aliased glyph
Glyph
A glyph is an element of writing: an individual mark on a written medium that contributes to the meaning of what is written. A glyph is made up of one or more graphemes....

 rendering. Paragraph layout can be controlled automatically or by the user, using a built-in "ruler
Ruler
A ruler, sometimes called a rule or line gauge, is an instrument used in geometry, technical drawing, printing and engineering/building to measure distances and/or to rule straight lines...

" object that can be attached to any text view. Spell checking is automatic, using a single dictionary used by all applications that uses the "squiggly underlining" convention introduced by Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

 (actually a dashed red underline in Cocoa). Unlimited Undo/Redo support is built in. Using only the built-in features, one can write a text editor application in as few as 10 lines of code. With new controller objects, this may fall to zero. This is in contrast to the TextEdit
TextEdit (API)
TextEdit was the name of a collection of application programming interfaces in the classic Mac OS for performing text editing.These APIs were originally designed to provide a common text handling system to support text entry fields in dialog boxes and other simple text editing within the Macintosh...

 APIs found in the earlier Mac OS.

When extensions are needed, Cocoa's use of Objective-C makes this a straightforward task. Objective-C includes the concept of "categories" which allows for modifications to an existing class "in-place". Functionality can be accomplished in a category without any changes to the original classes in the framework, or even access to its source. Under more common frameworks this same task would require the programmer to make a new subclass supporting the additional features, and then change all instances of the classes to this new class.

Implementations

The Cocoa frameworks are written in Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...

, and hence Objective-C is the preferred language for development of Cocoa applications. Java bindings
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...

 for the Cocoa frameworks (known as the "Java bridge") are also available but have not proven popular amongst Cocoa developers. Further, the need for runtime binding means many of Cocoa's key features are not available with Java. In 2005, Apple announced that the Java bridge was to be deprecated, meaning that features added to Cocoa in Mac OS X versions later than 10.4 would not be added to the Cocoa-Java programming interface.

Originally, Applescript Studio could be used to develop less complex Cocoa applications. However, as of Snow Leopard, it has been deprecated. It was replaced with ApplescriptObjC, which allows you to program in Applescript, while using Cocoa frameworks.

Third-party bindings available for other languages include Clozure CL
Clozure CL
Clozure CL is a Common Lisp implementation. It implements the full ANSI Common Lisp standard with several extensions...

, LispWorks
LispWorks
LispWorks is a commercial implementation and IDE for the Common Lisp programming language. The software runs on Microsoft Windows, Mac OS X , Linux, FreeBSD, Solaris and HP UX....

, PyObjC
PyObjC
PyObjC is a bidirectional bridge between Python and Objective-C. It allows Python scripts to use and extend existing Objective-C class libraries....

 (Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

), RubyCocoa
RubyCocoa
RubyCocoa is a Mac OS X framework that provides a bridge between the Ruby and the Objective-C programming languages, allowing the user to manipulate Objective-C objects from Ruby, and vice-versa. It makes it possible to write a Cocoa application completely in Ruby as well as to write an application...

 (Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

), CamelBones
CamelBones
CamelBones is a programming framework that allows one to use Mac OS X's Cocoa API through Perl. Its main author and maintainer was Sherm Pendley, before he died in 2011....

 (Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

), Cocoa#
Cocoa Sharp
Cocoa# is a bridge framework on Mac OS X to allow applications developed with the Mono runtime to access the Cocoa API. It provides direct access to the Cocoa API using a dot notation familiar to languages working on the Mono runtime such as C#....

, Monobjc
Monobjc
Monobjc is a bridge API for Mac OS X to allow applications that run on Mono runtime to access various Mac OS X API.It brings to .NET developers the ability to use in a totally transparent manner and with no native code, most of the Mac OS X API and especially Cocoa...

 (C#) and NObjective
NObjective
NObjective is a Mono to Cocoa bridge.NObjective is high-performance bridge between managed .NET and unmanaged Cocoa worlds. It provides automatically generated proxies for all Objective-C classes and can be used to export managed classes to unmanaged Objective-C runtime.Key features:* Lowest...

(C#). Nu
Nu (programming language)
Nu is an interpreted object-oriented programming language, with a Lisp-like syntax, created by Tim Burks as an alternative scripting language to program Mac OS X through its Cocoa application programming interface...

 uses the Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...

 object model directly, and therefore can use the Cocoa frameworks without requiring a binding.

There are also open source implementations of major parts of the Cocoa framework that allows cross-platform (including Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

) Cocoa application development, such as GNUstep
GNUstep
GNUstep is a free software implementation of Cocoa Objective-C libraries , widget toolkit, and application development tools not only for Unix-like operating systems, but also for Microsoft Windows. It is part of the GNU Project.GNUstep features a cross-platform, object-oriented development...

, and Cocotron.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK