Access the essential classes that define basic object behavior, data types, collections, and operating-system services. Incorporate design patterns and mechanisms that make your apps more efficient and robust.
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
The Foundation framework defines a base layer of Objective-C classes. In addition to providing a set of useful primitive object classes, it introduces several paradigms that define functionality not covered by the Objective-C language. The Foundation framework is designed with these goals in mind:
Provide a small set of basic utility classes.
Make software development easier by introducing consistent conventions for things such as deallocation.
Support Unicode strings, object persistence, and object distribution.
Provide a level of OS independence, to enhance portability.
The Foundation framework includes the root object class, classes representing basic data types such as strings and byte arrays, collection classes for storing other objects, classes representing system information such as dates, and classes representing communication ports. See Cocoa Objective-C Hierarchy for Foundation for a list of those classes that make up the Foundation framework.
The Foundation framework introduces several paradigms to avoid confusion in common situations, and to introduce a level of consistency across class hierarchies. This consistency is done with some standard policies, such as that for object ownership (that is, who is responsible for disposing of objects), and with abstract classes like
NSEnumerator. These new paradigms reduce the number of special and exceptional cases in an API and allow you to code more efficiently by reusing the same mechanisms with various kinds of objects.
Foundation Framework Classes
The Foundation class hierarchy is rooted in the Foundation framework’s
NSObject class. The remainder of the Foundation framework consists of several related groups of classes as well as a few individual classes. Many of the groups form what are called class clusters—abstract classes that work as umbrella interfaces to a versatile set of private subclasses.
NSMutable, for example, act as brokers for instances of various private subclasses optimized for different kinds of storage needs. Depending on the method you use to create a string, an instance of the appropriate optimized class will be returned to you.
Many of these classes have closely related functionality:
NSDataprovides object-oriented storage for arrays of bytes.
NSNumberprovide object-oriented storage for arrays of simple C data values.
NSSetprovide storage for Objective-C objects of any class.
Text and Strings: The
NSMutableclasses represent text strings and provide methods for searching, combining, and comparing strings. An
Scannerobject is used to scan numbers and words from an
NSCharacterrepresents various groupings of characters that are used by
See String Programming Guide for more information.
Dates and Times: The
NSCalendarclasses store times and dates and represent calendrical information. They offer methods for calculating date and time differences. Together with
NSLocale, they provide methods for displaying dates and times in many formats, and for adjusting times and dates based on location in the world.
See Date and Time Programming Guide for more information.
Application Coordination and Timing:
Notificationprovide systems that an object can use to notify all interested observers of changes that occur. You can use an
Timerobject to send a message to another object at specific intervals.
See Notification Programming Topics for more information.
Object Distribution and Persistence: The data that an object contains can be represented in an architecture-independent way using
NSCoderclass and its subclasses take this process a step further by allowing class information to be stored along with the data. The resulting representations are used for archiving and for object distribution.
See Archives and Serializations Programming Guide for more information.
Operating-System Services: Several classes are designed to insulate you from the idiosyncrasies of various operating systems.
Fileprovides a consistent interface for file operations (creating, renaming, deleting, and so on).
Processlet you create multithreaded applications and query the environment in which an application runs.
See File System Programming Guide for more information.
URL Loading System: A set of classes and protocols that allow your app to access content referenced by a URL, as represented by the
URLResponseobjects represent requests and responses sent and received by an
URLSessionobject. Additional functionality is provided by helper classes, including
URLProtocolfor protocol support,
URLCredentialfor authentication and credentials,
HTTPCookiefor cookie storage, and
URLCachefor cache management.
See URL Session Programming Guide for more information.