Foundation is the base framework underneath every Cocoa and Cocoa Touch application. It contains no user-interface code; instead, as Apple’s technology overview puts it, “the classes of the Foundation framework implement data management, file access, process notification, network communication, and other low-level features.” Foundation provides the fundamental value types, collections, and object behaviors that the rest of Apple’s frameworks build upon, which is why AppKit and UIKit both depend directly on it.
At the center of Foundation is NSObject, the root class from which nearly all Objective-C classes inherit their basic runtime behavior. Around it sit the workhorse value and collection classes. Apple’s “Programming with Objective-C” guide explains that strings “are usually represented as instances of the NSString class,” with NSMutableString as “the mutable subclass of NSString” that lets you “change its character contents at runtime.” For grouping objects, Apple notes that “most collections in Objective-C code are instances of one of the Cocoa and Cocoa Touch collection classes, like NSArray, NSSet and NSDictionary,” and that these “use strong references to keep track of their contents.”
Foundation also defines the conventions that make Apple’s object graphs persistable and serializable. The framework’s archiving system (NSCoding, NSKeyedArchiver) is what allows interface designs and document data to be flattened to disk and reconstituted later, the same mechanism that underlies Interface Builder’s nib files.
Like the rest of Cocoa, Foundation is an inheritance from NeXT. It was specified as part of OpenStep, the portable framework definition NeXT and Sun Microsystems published in the mid-1990s, which separated the Foundation and Application kits from the underlying operating system. That portability is the whole point of the “NS” prefix on Foundation’s class names: it stands for NeXTSTEP, and it survives on classes like NSString and NSArray to this day.
Because Foundation is the layer with no GUI, it was the natural shared core when Apple split its frameworks for the iPhone. AppKit was replaced by UIKit for touch devices, but Foundation carried across essentially unchanged into Cocoa Touch, so the same NSString, NSArray, and NSObject power both Mac and iOS apps. When Swift arrived in 2014, it bridged to these Foundation types directly, and Apple later open-sourced a cross-platform reimplementation (swift-corelibs-foundation) so the framework could run beyond Apple’s own operating systems.