HOME

TheInfoList



OR:

Cocoa is
Apple An apple is an edible fruit produced by an apple tree (''Malus domestica''). Apple fruit tree, trees are agriculture, cultivated worldwide and are the most widely grown species in the genus ''Malus''. The tree originated in Central Asia, wh ...
's native
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of p ...
application programming interface An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how t ...
(API) for its
desktop A desktop traditionally refers to: * The surface of a desk (often to distinguish office appliances that fit on a desk, such as photocopiers and printers, from larger equipment covering its own area on the floor) Desktop may refer to various compu ...
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
. Cocoa consists of the
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 (for NeXTSTEP). It is a ...
,
Application Kit AppKit (formally Application Kit) is a graphical user interface toolkit. It initially served as the UI framework for NeXTSTEP. Along with Foundation and Display PostScript, it became one of the core parts of the OpenStep specification of APIs. L ...
, and
Core Data Core Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0.Apple, "Core Data Tutorial for iPhone OS". It allows data orga ...
frameworks, as included by the Cocoa.h header file, and the libraries and frameworks included by those, such as the C standard library and the Objective-C runtime.Mac Technology Overview: OS X Frameworks
Developer.apple.com. Retrieved on September 18, 2013.
Cocoa applications are typically developed using the development tools provided by Apple, specifically
Xcode Xcode is Apple's integrated development environment (IDE) for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS. It was initially released in late 2003; the latest stable release is version 14.2, released on December 13, ...
(formerly Project Builder) and
Interface Builder Interface Builder is a software development application for Apple's macOS operating system. It is part of Xcode (formerly Project Builder), the Apple Developer developer's toolset. Interface Builder allows Cocoa and Carbon developers to creat ...
(now part of Xcode), using the
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
or
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
. However, the Cocoa programming environment can be accessed using other tools. It is also possible to write Objective-C Cocoa programs in a simple
text editor A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be us ...
and build it manually with
GNU Compiler Collection The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems. The Free Software Foundation (FSF) distributes GCC as free software ...
(GCC) or
Clang Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection ...
from the command line or from a
makefile In software development, Make is a build automation tool that automatically builds executable programs and libraries from source code by reading files called ''Makefiles'' which specify how to derive the target program. Though integrated devel ...
. For
end users In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ultimately use a product. The end user stands in contrast to users who support or maintain the product, such as sysops, system administrato ...
, Cocoa
applications Application may refer to: Mathematics and computing * Application software, computer software designed to help the user to perform specific tasks ** Application layer, an abstraction layer that specifies protocols and interface methods used in a c ...
are those written using the Cocoa programming environment. Such applications usually have a familiar look and feel, since the Cocoa programming environment provides a lot of common UI elements (such as buttons, scroll bars, etc.), and automates many aspects of an application to comply with Apple's human interface guidelines. For
iOS iOS (formerly iPhone OS) is a mobile operating system created and developed by Apple Inc. exclusively for its hardware. It is the operating system that powers many of the company's mobile devices, including the iPhone; the term also include ...
,
iPadOS iPadOS is a mobile operating system developed by Apple Inc. for its iPad line of tablet computers. It is a rebranded variant of iOS, the operating system used by Apple's iPhones, renamed to reflect the diverging features of the two product ...
,
tvOS tvOS (formerly known as Apple TV Software) is an operating system developed by Apple Inc. for the Apple TV, a digital media player. In the first-generation Apple TV, Apple TV Software was based on Mac OS X. Starting with the second-generation, ...
, and
watchOS watchOS is the operating system of the Apple Watch, developed by Apple Inc. It is based on iOS, the operating system used by the iPhone, and has many similar features. It was released on April 24, 2015, along with the Apple Watch, the only dev ...
, a similar API exists, named
Cocoa Touch Cocoa Touch is the application development environment for building software programs to run on iOS for the iPhone and iPod Touch, iPadOS for the iPad, watchOS for the Apple Watch, and tvOS for the Apple TV, from Apple Inc. Cocoa Touch ...
, which includes
gesture recognition Gesture recognition is a topic in computer science and language technology with the goal of interpreting human gestures via mathematical algorithms. It is a subdiscipline of computer vision. Gestures can originate from any bodily motion or sta ...
,
animation Animation is a method by which image, still figures are manipulated to appear as Motion picture, moving images. In traditional animation, images are drawn or painted by hand on transparent cel, celluloid sheets to be photographed and exhibited ...
, and a different set of graphical control elements. It is used in
applications Application may refer to: Mathematics and computing * Application software, computer software designed to help the user to perform specific tasks ** Application layer, an abstraction layer that specifies protocols and interface methods used in a c ...
for Apple devices such as the iPhone, the
iPod Touch The iPod Touch (stylized as iPod touch) is a discontinued line of iOS-based mobile devices designed and marketed by Apple Inc. with a touchscreen-controlled user interface. As with other iPod models, the iPod Touch can be used as a music pl ...
, the
iPad The iPad is a brand of iOS and iPadOS-based tablet computers that are developed by Apple Inc. The iPad was conceived before the related iPhone but the iPhone was developed and released first. Speculation about the development, operating s ...
, the Apple TV, and the
Apple Watch Apple Watch is a line of smartwatches produced by Apple Inc. It incorporates fitness tracking, health-oriented capabilities, and wireless telecommunication, and integrates with iOS and other Apple products and services. The Apple Watch was rel ...
.


History

Cocoa continues the lineage of several
software framework In computer programming, a software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software. It provides a standard ...
s (mainly the ''App Kit'' and ''Foundation Kit'') from the
NeXTSTEP NeXTSTEP is a discontinued object-oriented, multitasking operating system based on the Mach kernel and the UNIX-derived BSD. It was developed by NeXT Computer in the late 1980s and early 1990s and was initially used for its range of proprieta ...
and
OpenStep OpenStep is a defunct object-oriented application programming interface (API) specification for a legacy object-oriented operating system, with the basic goal of offering a NeXTSTEP-like environment on non-NeXTSTEP operating systems. OpenStep wa ...
programming environments developed by
NeXT Next may refer to: Arts and entertainment Film * ''Next'' (1990 film), an animated short about William Shakespeare * ''Next'' (2007 film), a sci-fi film starring Nicolas Cage * '' Next: A Primer on Urban Painting'', a 2005 documentary film Lit ...
in the 1980s and 1990s. Apple acquired NeXT in December 1996, and subsequently went to work on the
Rhapsody Rhapsody may refer to: * A work of epic poetry, or part of one, that is suitable for recitation at one time ** Rhapsode, a classical Greek professional performer of epic poetry Computer software * Rhapsody (online music service), an online m ...
operating system that was to be the direct successor of OpenStep. It was to have had an emulation base for classic Mac OS applications, named ''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. Thus, Cocoa classes begin with the letters ''NS'', such as NSString or NSArray. These stand for the original proprietary term for the OpenStep framework, NeXTSTEP. Much of the work that went into developing OpenStep was applied to developing Mac OS X, Cocoa being the most visible part. However, differences exist. For example, NeXTSTEP and OpenStep used
Display PostScript Display PostScript (or DPS) is a 2D graphics engine system for computers which uses the PostScript (PS) imaging model and language (originally developed for computer printing) to generate on-screen graphics. To the basic PS system, DPS adds a num ...
for on-screen display of text and graphics, while Cocoa depends on Apple's
Quartz Quartz is a hard, crystalline mineral composed of silica (silicon dioxide). The atoms are linked in a continuous framework of SiO4 silicon-oxygen tetrahedra, with each oxygen being shared between two tetrahedra, giving an overall chemical form ...
(which uses the
Portable Document Format Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
(PDF) imaging model, but not its underlying technology). Cocoa also has a level of Internet support, including the NSURL and
WebKit WebKit is a browser engine developed by Apple and primarily used in its Safari web browser, as well as on the iOS and iPadOS version of any web browser. WebKit is also used by the BlackBerry Browser, PlayStation consoles beginning from the PS ...
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScri ...
classes, and others, while OpenStep had only rudimentary support for managed network connections via NSFileHandle classes and
Berkeley sockets Berkeley sockets is an application programming interface (API) for Internet sockets and Unix domain sockets, used for inter-process communication (IPC). It is commonly implemented as a library of linkable modules. It originated with the 4.2BSD ...
. The resulting software framework received the name ''Cocoa'' for the sake of expediency, because the name had already been trademarked by Apple. For many years before this present use of the name, Apple's ''Cocoa'' trademark had originated as the name of a multimedia project design application for children. The application was originally developed at the
Apple Advanced Technology Group The Advanced Technology Group (ATG) was a corporate research laboratory at Apple Computer from 1986 to 1997. ATG was an evolution of Apple's Education Research Group (ERG) and was started by Larry Tesler in October 1986 to study long-term res ...
under the name ''KidSim'', and was then renamed and trademarked as "Cocoa". The name, coined by Peter Jensen who was hired to develop Cocoa for Apple, was intended to evoke "Java for kids", as it ran embedded in web pages. The trademark, and thus the name "Cocoa", was re-used to avoid the delay which would have occurred while registering a new
trademark A trademark (also written trade mark or trade-mark) is a type of intellectual property consisting of a recognizable sign, design, or expression that identifies products or services from a particular source and distinguishes them from others ...
for this software framework. The original "Cocoa" program was discontinued at Apple in one of the rationalizations that followed Steve Jobs's return to Apple. It was then licensed to a third party and marketed as Stagecast Creator until 2014.


Memory management

One feature of the Cocoa environment is its facility for managing dynamically allocated memory.
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 (for NeXTSTEP). It is a ...
's NSObject class, from which most classes, both vendor and user, are derived, implements a reference counting scheme for memory management. Objects that derive from the NSObject root class respond to a retain and a release message, and keep a retain count. A method titled retainCount exists, but contrary to its name, will usually not return the exact retain count of an object. It is mainly used for system-level purposes. Invoking it manually is not recommended by Apple. 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 by a procedure similar to a C++ ''destructor''. dealloc is not guaranteed to be invoked. Starting with Objective-C 2.0, the Objective-C runtime implemented an optional
garbage collector A waste collector, also known as a garbageman, garbage collector, trashman (in the US), binman or (rarely) dustman (in the UK), is a person employed by a public or private enterprise to collect and dispose of municipal solid waste (refuse) and r ...
, which is now obsolete and deprecated in favor of
Automatic Reference Counting Automatic Reference Counting (ARC) is a memory management feature of the Clang compiler providing automatic reference counting for the Objective-C and Swift programming languages. At compile time, it inserts into the object code messages retain a ...
(ARC). In this model, the runtime turned Cocoa reference counting operations such as "retain" and "release" into
no-op In computer science, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is a machine language instruction and its assembly language mnemonic, programming language statement, or computer protocol command that does nothing. Mac ...
s. The garbage collector does not exist on the
iOS iOS (formerly iPhone OS) is a mobile operating system created and developed by Apple Inc. exclusively for its hardware. It is the operating system that powers many of the company's mobile devices, including the iPhone; the term also include ...
implementation of Objective-C 2.0. Garbage collection in Objective-C ran on a low-priority background thread, and can halt on Cocoa's user events, with the intention of keeping the user experience responsive. The legacy garbage collector is still available on Mac OS X version 10.13, but no Apple-provided applications use it. In 2011, the
LLVM LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate repre ...
compiler introduced
Automatic Reference Counting Automatic Reference Counting (ARC) is a memory management feature of the Clang compiler providing automatic reference counting for the Objective-C and Swift programming languages. At compile time, it inserts into the object code messages retain a ...
(ARC), 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 of three
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
object libraries called ''
frameworks A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of. Framework may refer to: Computing * Application framework, used to implement the structure of an application for an op ...
''. Frameworks are functionally similar to
shared libraries In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and su ...
, 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
bundle Bundle or Bundling may refer to: * Bundling (packaging), the process of using straps to bundle up items Biology * Bundle of His, a collection of heart muscle cells specialized for electrical conduction * Bundle of Kent, an extra conduction pat ...
, containing the aforementioned items in standard locations. * ''
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 (for NeXTSTEP). It is a ...
'' (''Foundation''), first appeared in Enterprise Objects Framework on NeXTSTEP 3. It was developed as part of the OpenStep work, and subsequently became the basis for OpenStep's AppKit when that system was released in 1994. On macOS, Foundation is based on
Core Foundation Core Foundation (also called CF) is a C application programming interface (API) written by Apple for its operating systems, and is a mix of low-level routines and wrapper functions. Most Core Foundation routines follow a certain naming conventi ...
. Foundation is a generic object-oriented library providing string and value manipulation,
containers A container is any receptacle or enclosure for holding a product used in storage, packaging, and transportation, including shipping. Things kept inside of a container are protected on several sides by being inside of its structure. The term ...
and
iteration Iteration is the repetition of a process in order to generate a (possibly unbounded) sequence of outcomes. Each repetition of the process is a single iteration, and the outcome of each iteration is then the starting point of the next iteration. ...
,
distributed computing A distributed system is a system whose components are located on different computer network, networked computers, which communicate and coordinate their actions by message passing, passing messages to one another from any system. Distributed com ...
,
event loop In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider" (that generally ...
s (run loops), and other functions that are not directly tied to the graphical user interface. The "NS" prefix, used for all classes and constants in the framework, comes from Cocoa's OPENSTEP heritage, which was jointly developed by NeXT and
Sun Microsystems Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, the ...
. * ''
Application Kit AppKit (formally Application Kit) is a graphical user interface toolkit. It initially served as the UI framework for NeXTSTEP. Along with Foundation and Display PostScript, it became one of the core parts of the OpenStep specification of APIs. L ...
'' (''AppKit'') is directly descended from the original NeXTSTEP Application Kit. It contains code programs can use to create and interact with
graphical user interface The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, inste ...
s. AppKit is built on top of Foundation, and uses the same ''NS'' prefix. * ''
Core Data Core Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0.Apple, "Core Data Tutorial for iPhone OS". It allows data orga ...
'' is the object persistence framework included with Foundation and Cocoa and found in Cocoa.h. 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
Portable Document Format Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
(PDF) drawing model provided by
Quartz Quartz is a hard, crystalline mineral composed of silica (silicon dioxide). The atoms are linked in a continuous framework of SiO4 silicon-oxygen tetrahedra, with each oxygen being shared between two tetrahedra, giving an overall chemical form ...
. This allows creating custom drawing content using
PostScript PostScript (PS) is a page description language in the electronic publishing and desktop publishing realm. It is a dynamically typed, concatenative programming language. It was created at Adobe Systems by John Warnock, Charles Geschke, Doug Br ...
-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 on the unique aspects of an application's content.


Model–view–controller

The
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
teams at
Xerox PARC PARC (Palo Alto Research Center; formerly Xerox PARC) is a research and development company in Palo Alto, California. Founded in 1969 by Jacob E. "Jack" Goldman, chief scientist of Xerox Corporation, the company was originally a division of Xero ...
eventually settled on a design philosophy that led to easy development and high code reuse. Named ''
model–view–controller Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of infor ...
'' (MVC), the concept breaks an application into three sets of interacting object classes: * Model classes represent problem domain data and operations (such as lists of people/departments/budgets; documents containing sections/paragraphs/footnotes of stylized text). * View classes implement visual representations and affordances for human-computer interaction (such as scrollable grids of captioned icons and pop-up menus of possible operations). * Controller classes contain logic that surfaces model data as view representations, maps affordance-initiated user actions to model operations, and maintains state to keep the two synchronized. Cocoa's design is a fairly, but not absolutely 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. No stock class 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 is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0.Apple, "Core Data Tutorial for iPhone OS". It allows data orga ...
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 when necessary, saving data to disk, and reading it back in. In providing framework support for all three MVC domains, 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 needed, usually organized according to the
chain-of-responsibility pattern In object-oriented design, the chain-of-responsibility pattern is a behavioral design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains logic that defines the types of command obj ...
. While Cocoa retains this approach for the most part, Objective-C's
late binding In computing, late binding or dynamic linkage—though not an identical process to dynamically linking imported code libraries—is a computer programming mechanism in which the method being called upon an object, or the function being called ...
opens up more flexibility. Under Objective-C, methods are represented by a ''selector'', a string describing the method to call. When a message is sent, the selector is sent into the Objective-C runtime, matched against a list of available methods, and the method's ''implementation'' is called. Since the selector is text data, this lets it 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 allows 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. In traditional languages, this late binding is impossible. KVC leads to great design flexibility. An object's type need not be known, yet any property of that object can be discovered using KVC. Also, by extending this system using something Cocoa terms ''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, formally The Unicode Standard,The formal version reference is is an information technology Technical standard, standard for the consistent character encoding, encoding, representation, and handling of Character (computing), text expre ...
strings String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * ''Strings'' (1991 film), a Canadian anim ...
, and the
NSText The Cocoa text system (formerly known simply by the primary class name NSText) is the linked network of classes, protocols, interfaces and objects that provide typography and text field editing capabilities and to Cocoa applications on Apple's ma ...
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 is the art and technique of arranging type to make written language legible, readable and appealing when displayed. The arrangement of type involves selecting typefaces, point sizes, line lengths, line-spacing ( leading), and ...
features such as
kerning In typography, kerning is the process of adjusting the spacing between Character (symbol), characters in a Typeface#Proportion, proportional font, usually to achieve a visually pleasing result. Kerning adjusts the space between individual le ...
, ligatures, running text around arbitrary
shape A shape or figure is a graphics, graphical representation of an object or its external boundary, outline, or external Surface (mathematics), surface, as opposed to other properties such as color, Surface texture, texture, or material type. A pl ...
s,
rotation Rotation, or spin, is the circular movement of an object around a '' central axis''. A two-dimensional rotating object has only one possible central axis and can rotate in either a clockwise or counterclockwise direction. A three-dimensional ...
, full Unicode support, and anti-aliased
glyph A glyph () is any kind of purposeful mark. In typography, a glyph is "the specific shape, design, or representation of a character". It is a particular graphical representation, in a particular typeface, of an element of written language. A g ...
rendering. Paragraph layout can be controlled automatically or by the user, using a built-in "
ruler A ruler, sometimes called a rule, line gauge, or scale, is a device used in geometry and technical drawing, as well as the engineering and construction industries, to measure distances or draw straight lines. Variants Rulers have long ...
" object that can be attached to any text view. Spell checking is automatic, using a system-wide set of language dictionaries. 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 towards zero. When extensions are needed, Cocoa's use of Objective-C makes this a straightforward task. Objective-C includes the concept of
categories
" which allows modifying 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. In other common languages, this same task requires deriving a new subclass supporting the added features, and then replacing all instances of the original class with instances of the new subclass.


Implementations and bindings

The Cocoa frameworks are written in
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
. Java bindings for the Cocoa frameworks (termed the ''Java bridge'') were also made available with the aim of replacing Objective-C with a more popular language but these bindings were unpopular among Cocoa developers and Cocoa's message passing semantics did not translate well to a statically-typed language such as Java. Cocoa's 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 macOS versions later than 10.4 would not be added to the Cocoa-Java programming interface. At Apple Worldwide Developers Conference (WWDC) 2014, Apple introduced a new programming language named
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
, which is intended to replace Objective-C.


AppleScriptObjC

Originally, AppleScript Studio could be used to develop simpler Cocoa applications. However, as of Snow Leopard, it has been deprecated. It was replaced with AppleScriptObjC, which allows programming in
AppleScript AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system aut ...
, while using Cocoa frameworks.


Other bindings

The Cocoa programming environment can be accessed using other tools with the aid of bridge mechanisms such as PasCocoa,
PyObjC PyObjC is a bidirectional bridge between the Python and Objective-C programming languages, allowing programmers to use and extend existing Objective-C libraries, such as Apple's Cocoa framework, using Python. PyObjC is used to develop macOS appl ...
, CamelBones,
RubyCocoa RubyCocoa is a macOS 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 c ...
, and a D/Objective-C Bridge. Third-party bindings available for other languages include
AppleScript AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system aut ...
,
Clozure CL Clozure CL (CCL) is a Common Lisp implementation. It implements the full ANSI Common Lisp standard with several extensions (CLOS MOP, threads, CLOS conditions, CLOS streams, ...). It contains a command line development environment, an experimenta ...
, Monobjc and
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 unma ...
( C#), Cocoa# (CLI), Cocodao and D/Objective-C Bridge,
LispWorks LispWorks is computer software, a proprietary implementation and integrated development environment (IDE) for the programming language Common Lisp. LispWorks was developed by the UK software company Harlequin Ltd., and first published in 1989. Ha ...
,
Object Pascal Object Pascal is an extension to the programming language Pascal (programming language), Pascal that provides object-oriented programming (OOP) features such as Class (computer programming), classes and Method (computer programming), methods. ...
, CamelBones (
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
),
PyObjC PyObjC is a bidirectional bridge between the Python and Objective-C programming languages, allowing programmers to use and extend existing Objective-C libraries, such as Apple's Cocoa framework, using Python. PyObjC is used to develop macOS appl ...
(
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
), FPC PasCocoa ( Lazarus and
Free Pascal Free Pascal Compiler (FPC) is a compiler for the closely related programming-language dialects Pascal and Object Pascal. It is free software released under the GNU General Public License, witexception clausesthat allow static linking against its ...
),
RubyCocoa RubyCocoa is a macOS 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 c ...
(
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
). A Ruby language implementation named
MacRuby MacRuby is a discontinued implementation of the Ruby language that ran on the Objective-C runtime and CoreFoundation framework under development by Apple Inc. which "was supposed to replace RubyCocoa". It targeted Ruby 1.9 and used the high per ...
, which removes the need for a bridge mechanism, was formerly developed by Apple, while Nu is a Lisp-like language that uses the
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
object model directly, and thus can use the Cocoa frameworks without needing a binding.


Other implementations

There are also open source implementations of major parts of the Cocoa framework, such as
GNUstep GNUstep is a free software implementation of the Cocoa (formerly OpenStep) Objective-C frameworks, widget toolkit, and application development tools for Unix-like operating systems and Microsoft Windows. It is part of the GNU Project. GNUste ...
and Cocotron,Cocotron
free software implementation of Cocoa.
which allow
cross-platform In computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several computing platforms. Some cross-platform software r ...
Cocoa application development to target other operating systems, such as
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
and
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
.


See also


References


Bibliography

* Aaron Hillegass: ''Cocoa Programming for Mac OS X'', Addison-Wesley, 3rd Edition 2008, Paperback, . * Stephen Kochan: ''Programming in Objective-C'', Sams, 1st Edition 2003, Paperback, . * Michael Beam,
James Duncan Davidson James Duncan Davidson is an American software developer and photographer. He's currently the Technology Advisor to Tobias Lütke, CEO of Shopify. While a software engineer at Sun Microsystems (1997–2001), Davidson created Tomcat, a Java-based ...
: ''Cocoa in a Nutshell'', O'Reilly, 1st Edition 2003, Paperback, . * Erick Tejkowski: ''Cocoa Programming for Dummies'', 1st Edition 2003, Paperback, . * * Paris Buttfield-Addison, Jon Manning: ''Learning Cocoa with Objective-C'', O'Reilly, 3rd Edition 2012, Paperback, . * Scott Anguish, Erik M. Buck, Donald A. Yacktman: ''Cocoa Programming'', Sams, 1st Edition 2002, Paperback, . * Erik M. Buck, Donald A. Yacktman: ''Cocoa Design Patterns'', Addison-Wesley Professional, 1st Edition 2009, Paperback, * Bill Cheeseman: ''Cocoa Recipes for Mac OS X'', Peachpit Press, 1st Edition 2002, Paperback, . *Andrew Duncan: ''Objective-C Pocket Reference, O'Reilly'', 1st Edition 2002, Paperback, .


External links

*
Mac Developer Library, Cocoa Layer
Apple's documentation
iDevApps
Mac programming forum
Cocoa Dev Central

Cocoa Dev

Stack Overflow: Cocoa
{{Widget toolkits MacOS APIs