Cocoa

Cocoa is Apple’s native object-oriented application environment for macOS. In Apple’s own technology overview, Cocoa is described in two senses: narrowly, as “the application layer of OS X” that is “primarily responsible for the appearance of apps and their responsiveness to user actions,” and more broadly, as the umbrella term that “frequently refers to all programmatic interfaces for app development.” In practice, a Cocoa application is built on two core frameworks: AppKit, for the user interface, and Foundation, for everything else.

Apple’s documentation identifies AppKit as “the key framework for Cocoa apps,” whose classes “implement the user interface (UI) of an app, including windows, dialogs, controls, menus, and event handling.” Foundation sits beneath it and “implement[s] data management, file access, process notification, network communication, and other low-level features.” The two are tightly coupled: as Apple notes, “AppKit has a direct dependency on Foundation because many of its methods and functions either take instances of Foundation classes as parameters, or return the instances as values.”

Cocoa is not a from-scratch Apple invention. Its frameworks descend directly from NeXTSTEP and the OpenStep specification that came to Apple when it acquired NeXT in 1996. AppKit is the direct successor of NeXTSTEP’s Application Kit, and Foundation carries forward the OpenStep Foundation library. The fingerprints are everywhere in the API: classes such as NSObject, NSString, NSArray, and NSWindow all carry the “NS” prefix, which stands for NeXTSTEP. Cocoa first shipped under that name with the release of Mac OS X in 2001.

Programming in Cocoa was, for most of its life, programming in Objective-C, the message-passing language Brad Cox built on top of C. Apple’s “Programming with Objective-C” guide shows the idioms a Cocoa developer used daily, from creating an NSString with the literal syntax @“Hello World!” to managing groups of objects with “the Cocoa and Cocoa Touch collection classes, like NSArray, NSSet and NSDictionary.” Cocoa applications were traditionally laid out visually in Interface Builder and stored their interface designs in nib files.

When Apple introduced the iPhone, it adapted Cocoa for touch devices as Cocoa Touch, replacing AppKit with UIKit while keeping Foundation essentially intact. And when Apple introduced Swift in 2014, Cocoa remained the framework target: Swift code calls the same AppKit and Foundation APIs, so the NeXT lineage continues to underpin Apple software even in its most modern language.