iOS Developer Library

Developer

Foundation Framework Reference

The Foundation Framework

Classes   Protocols   Other Reference  

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. NSString and NSMutableString, 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:

  • Data storage. NSData and NSString provide object-oriented storage for arrays of bytes. NSValue and NSNumber provide object-oriented storage for arrays of simple C data values. NSArray, NSDictionary, and NSSet provide storage for Objective-C objects of any class.

  • Text and strings. NSCharacterSet represents various groupings of characters that are used by the NSString and NSScanner classes. The NSString classes represent text strings and provide methods for searching, combining, and comparing strings. An NSScanner object is used to scan numbers and words from an NSString object.

  • Dates and times. The NSDate, NSTimeZone, and NSCalendar classes 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.

  • Application coordination and timing. NSNotification, NSNotificationCenter, and NSNotificationQueue provide systems that an object can use to notify all interested observers of changes that occur. You can use an NSTimer object to send a message to another object at specific intervals.

  • Object creation and disposal. NSAutoreleasePool is used to implement the delayed-release feature of the Foundation framework.

  • Object distribution and persistence. The data that an object contains can be represented in an architecture-independent way using NSPropertyListSerialization. The NSCoder 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.

  • Operating-system services. Several classes are designed to insulate you from the idiosyncrasies of various operating systems. NSFileManager provides a consistent interface for file operations (creating, renaming, deleting, and so on). NSThread and NSProcessInfo let you create multithreaded applications and query the environment in which an application runs.

  • URL loading system. A set of classes and protocols provide access to common Internet protocols.

Classes

NSObject

NSObject is the root class of most Objective-C class hierarchies.

NSArray

NSArray and its subclass NSMutableArray manage ordered collections of objects called arrays.

NSMutableArray

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects.

NSAssertionHandler

NSAssertionHandler objects are automatically created to handle false assertions.

NSAttributedString

An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string.

NSMutableAttributedString

NSMutableAttributedString declares the programmatic interface to objects that manage mutable attributed strings.

NSAutoreleasePool

The NSAutoreleasePool class is used to support Cocoa’s reference-counted memory management system.

NSBundle

An NSBundle object represents a location in the file system that groups code and resources that can be used in a program.

NSCache

An NSCache object is a collection-like container, or cache, that stores key-value pairs, similar to the NSDictionary class.

NSCachedURLResponse

An NSCachedURLResponse object represents a cached response to a URL request.

NSCalendar

Calendars encapsulate information about systems of reckoning time in which the beginning, length, and divisions of a year are defined.

NSCharacterSet

An NSCharacterSet object represents a set of Unicode-compliant characters.

NSMutableCharacterSet

The NSMutableCharacterSet class declares the programmatic interface to objects that manage a modifiable set of Unicode characters.

NSCoder

The NSCoder abstract class declares the interface used by concrete subclasses to transfer objects and other values between memory and some other format.

NSKeyedArchiver

NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file.

NSKeyedUnarchiver

NSKeyedUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive.

NSCondition

The NSCondition class implements a condition variable whose semantics follow those used for POSIX-style conditions.

NSConditionLock

The NSConditionLock class defines objects whose locks can be associated with specific, user-defined conditions.

NSData

NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers.

NSMutableData

NSMutableData (and its superclass NSData) provide data objects, object-oriented wrappers for byte buffers.

NSPurgeableData

You should use the NSPurgeableData class when you have objects with bytes that can be discarded when no longer needed.

NSDate

NSDate objects represent a single point in time.

NSDateComponents

NSDateComponents encapsulates the components of a date in an extendable, object-oriented manner.

NSDecimalNumberHandler

NSDecimalNumberHandler is a class that adopts the NSDecimalNumberBehaviors protocol.

NSDictionary

The NSDictionary class declares the programmatic interface to objects that manage immutable associations of keys and values.

NSMutableDictionary

The NSMutableDictionary class declares the programmatic interface to objects that manage mutable associations of keys and values.

NSEnumerator

NSEnumerator is an abstract class, instances of whose subclasses enumerate collections of other objects, such as arrays and dictionaries.

NSDirectoryEnumerator

An NSDirectoryEnumerator object enumerates the contents of a directory, returning the pathnames of all files and directories contained within that directory.

NSError

An NSError object encapsulates richer and more extensible error information than is possible using only an error code or error string.

NSException

NSException is used to implement exception handling and contains information about an exception.

NSExpression

NSExpression is used to represent expressions in a predicate.

NSExtensionContext

An NSExtensionContext object represents the host app context from which an app extension is invoked.

NSExtensionItem

An NSExtensionItem object is an immutable collection of values representing different aspects of an item for the extension to act upon.

NSFileAccessIntent

The NSFileAccessIntent class stores the details of coordinated-read and coordinated-write operations.

NSFileCoordinator

The NSFileCoordinator class coordinates the reading and writing of files and directories among multiple processes and objects in the same process.

NSFileHandle

The NSFileHandle class is an object-oriented wrapper for a file descriptor.

NSFileManager

An NSFileManager object lets you examine the contents of the file system and make changes to it.

NSFileSecurity

The NSFileSecurity class is an Objective-C stub class that is transparently bridged to CFFileSecurity.

NSFileVersion

An NSFileVersion object represents a snapshot of a file at a specific point in time.

NSFileWrapper

The NSFileWrapper class provides access to the attributes and contents of file-system nodes.

NSFormatter

NSFormatter is an abstract class that declares an interface for objects that create, interpret, and validate the textual representation of cell contents.

NSByteCountFormatter

The NSByteCountFormatter class converts a byte count value into a textual representation that is formatted with the appropriate byte modifier (KB, MB, GB and so on).

NSDateComponentsFormatter

An NSDateComponentsFormatter object takes quantities of time and formats them as a user-readable string.

NSDateFormatter

Instances of NSDateFormatter create string representations of NSDate objects, and convert textual representations of dates and times into NSDate objects.

NSDateIntervalFormatter

An NSDateIntervalFormatter object creates user-readable strings from pairs of dates.

NSEnergyFormatter

The NSEnergyFormatter class provides properly formatted, localized descriptions of energy values.

NSLengthFormatter

The NSLengthFormatter class provides properly formatted, localized descriptions of linear distances (for example, length and height measurements).

NSMassFormatter

The NSMassFormatter class provides properly formatted, localized descriptions of mass and weight values.

NSNumberFormatter

Instances of NSNumberFormatter format the textual representation of cells that contain NSNumber objects and convert textual representations of numeric values into NSNumber objects.

NSHTTPCookie

An NSHTTPCookie object represents an HTTP cookie.

NSHTTPCookieStorage

NSHTTPCookieStorage implements a singleton object (shared instance) that manages storage of cookies.

NSHashTable

NSHashTable is modeled after NSSet but provides different options, in particular to support weak relationships.

NSIndexPath

The NSIndexPath class represents the path to a specific node in a tree of nested array collections.

NSIndexSet

The NSIndexSet class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used.

NSMutableIndexSet

The NSMutableIndexSet class represents a mutable collection of unique unsigned integers, known as indexes because of the way they are used.

NSInvocation

An NSInvocation is an Objective-C message rendered static, that is, it is an action turned into an object.

NSItemProvider

An NSItemProvider object provides a lazy and secure way to convey data between a host app and extension.

NSJSONSerialization

You use the NSJSONSerialization class to convert JSON to Foundation objects and convert Foundation objects to JSON.

NSLinguisticTagger

The NSLinguisticTagger class is used to automatically segment natural-language text and tag it with information, such as parts of speech.

NSLocale

Locales encapsulate information about linguistic, cultural, and technological conventions and standards.

NSLock

An NSLock object is used to coordinate the operation of multiple threads of execution within the same application.

NSMapTable

NSMapTable is a mutable collection modeled after NSDictionary but provides different options.

NSMetadataItem

The NSMetadataItem class represents the metadata associated with a file, providing a simple interface to retrieve the available attribute names and values.

NSMetadataQuery

The NSMetadataQuery class encapsulates the functionality provided by the MDQuery opaque type for querying the Spotlight metadata.

NSMetadataQueryAttributeValueTuple

The NSMetadataQueryAttributeValueTuple class represents attribute-value tuples, which are objects that contain the attribute name and value of a metadata attribute.

NSMetadataQueryResultGroup

The NSMetadataQueryResultGroup class represents a collection of grouped attribute results returned by an NSMetadataQuery object.

NSMethodSignature

An NSMethodSignature object records type information for the arguments and return value of a method.

NSNetService

The NSNetService class represents a network service, either one your application publishes or is a client of.

NSNetServiceBrowser

The NSNetServiceBrowser class defines an interface for finding published services on a network using multicast DNS.

NSNotification

NSNotification objects encapsulate information so that it can be broadcast to other objects by an NSNotificationCenter object.

NSNotificationCenter

An NSNotificationCenter object (or simply, notification center) provides a mechanism for broadcasting information within a program.

NSNotificationQueue

NSNotificationQueue objects (or simply notification queues) act as buffers for notification centers (instances of NSNotificationCenter).

NSNull

The NSNull class defines a singleton object used to represent null values in collection objects (which don’t allow nil values).

NSOperation

The NSOperation class is an abstract class you use to encapsulate the code and data associated with a single task.

NSBlockOperation

The NSBlockOperation class is a concrete subclass of NSOperation that manages the concurrent execution of one or more blocks.

NSInvocationOperation

The NSInvocationOperation class is a concrete subclass of NSOperation that manages the execution of a single encapsulated task specified as an invocation.

NSOperationQueue

The NSOperationQueue class regulates the execution of a set of NSOperation objects.

NSOrderedSet

NSOrderedSet and its subclass, NSMutableOrderedSet, declare the programmatic interfaces to an ordered collection of objects.

NSMutableOrderedSet

NSMutableOrderedSet class declares the programmatic interface to a mutable, ordered collection of distinct objects.

NSOrthography

The NSOrthography class describes the linguistic content of a piece of text, typically used for the purposes of spelling and grammar checking.

NSPipe

NSPipe objects provide an object-oriented interface for accessing pipes.

NSPointerArray

NSPointerArray is a mutable collection modeled after NSArray but it can also hold NULL values, which can be inserted or extracted (and which contribute to the object’s count).

NSPointerFunctions

An instance of NSPointerFunctions defines callout functions appropriate for managing a pointer reference held somewhere else.

NSPort

NSPort is an abstract class that represents a communication channel.

NSMachPort

NSMachPort is a subclass of NSPort that can be used as an endpoint for distributed object connections (or raw messaging).

NSMessagePort

NSMessagePort is a subclass of NSPort that can be used as an endpoint for distributed object connections (or raw messaging).

NSPredicate

The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.

NSComparisonPredicate

NSComparisonPredicate is a subclass of NSPredicate that you use to compare expressions.

NSCompoundPredicate

NSCompoundPredicate is a subclass of NSPredicate used to represent logical “gate” operations (AND/OR/NOT) and comparison operations.

NSProcessInfo

The NSProcessInfo class provides methods to access information about the current process.

NSProgress

The NSProgress class provides a self-contained mechanism for progress reporting.

NSPropertyListSerialization

The NSPropertyListSerialization class provides methods that convert property list objects to and from several serialized formats.

NSRecursiveLock

NSRecursiveLock defines a lock that may be acquired multiple times by the same thread without causing a deadlock, a situation where a thread is permanently blocked waiting for itself to relinquish a lock.

NSRegularExpression

The NSRegularExpression class is used to represent and apply regular expressions to Unicode strings.

NSDataDetector

The NSDataDetector class is a specialized subclass of the NSRegularExpression class designed to match data detectors.

NSRunLoop

The NSRunLoop class declares the programmatic interface to objects that manage input sources.

NSScanner

The NSScanner class is an abstract superclass of a class cluster that declares the programmatic interface for an object that scans values from an NSString object.

NSSet

The NSSet, NSMutableSet, and NSCountedSet classes declare the programmatic interface to an unordered collection of objects.

NSMutableSet

The NSMutableSet class declares the programmatic interface to a mutable, unordered collection of distinct objects.

NSCountedSet

The NSCountedSet class declares the programmatic interface to a mutable, unordered collection of indistinct objects.

NSSortDescriptor

An instance of NSSortDescriptor describes a basis for ordering objects by specifying the property to use to compare the objects, the method to use to compare the properties, and whether the comparison should be ascending or descending.

NSStream

NSStream is an abstract class for objects representing streams.

NSInputStream

NSInputStream is a subclass of NSStream that provides read-only stream functionality.

NSOutputStream

The NSOutputStream class is a subclass of NSStream that provides write-only stream functionality.

NSString

The NSString class declares the programmatic interface for an object that manages immutable strings.

NSMutableString

The NSMutableString class declares the programmatic interface to an object that manages a mutable string—that is, a string whose contents can be edited—that conceptually represents an array of Unicode characters.

NSTextCheckingResult

NSTextCheckingResult is a class used to describe items located by text checking.

NSThread

An NSThread object controls a thread of execution.

NSTimeZone

NSTimeZone is an abstract class that defines the behavior of time zone objects.

NSTimer

You use the NSTimer class to create timer objects or, more simply, timers.

NSURL

An NSURL object represents a URL that can potentially contain the location of a resource on a remote server, the path of a local file on disk, or even an arbitrary piece of encoded data.

NSURLAuthenticationChallenge

NSURLAuthenticationChallenge encapsulates a challenge from a server requiring authentication from the client.

NSURLCache

The NSURLCache class implements the caching of responses to URL load requests by mapping NSURLRequest objects to NSCachedURLResponse objects.

NSURLComponents

The NSURLComponents class is a class that is designed to parse URLs based on RFC 3986 and to construct URLs from their constituent parts.

NSURLConnection

An NSURLConnection object lets you load the contents of a URL by providing a URL request object.

NSURLCredential

NSURLCredential is an immutable object representing an authentication credential consisting of authentication information specific to the type of credential and the type of persistent storage to use, if any.

NSURLCredentialStorage

NSURLCredentialStorage implements a singleton (shared object) that manages the credential storage.

NSURLProtectionSpace

An NSURLProtectionSpace object represents a server or an area on a server, commonly referred to as a realm, that requires authentication.

NSURLProtocol

NSURLProtocol is an abstract class that provides the basic structure for performing protocol-specific loading of URL data.

NSURLQueryItem

An NSURLQueryItem object represents a single name/value pair for an item in the query portion of a URL.

NSURLRequest

NSURLRequest objects represent a URL load request in a manner independent of protocol and URL scheme.

NSMutableURLRequest

NSMutableURLRequest is a subclass of NSURLRequest provided to aid developers who may find it more convenient to mutate a single request object for a series of URL load requests instead of creating an immutable NSURLRequest object for each load.

NSURLResponse

The NSURLResponse class encapsulates the metadata associated with the response to a a URL load request in a manner independent of protocol and URL scheme.

NSHTTPURLResponse

The NSHTTPURLResponse class is a subclass of NSURLResponse that provides methods for accessing information specific to HTTP protocol responses.

NSURLSession

The NSURLSession class and related classes provide an API for downloading content via HTTP.

NSURLSessionConfiguration

An NSURLSessionConfiguration object defines the behavior and policies to use when uploading and downloading data using an NSURLSession object.

NSURLSessionTask

The NSURLSessionTask class is the base class for tasks in a URL session.

NSURLSessionDataTask

An NSURLSessionDataTask is a concrete subclass of NSURLSessionTask.

NSURLSessionUploadTask

The NSURLSessionUploadTask class is a subclass of NSURLSessionDataTask, which in turn is a concrete subclass of NSURLSessionTask.

NSURLSessionDownloadTask

An NSURLSessionDownloadTask is a concrete subclass of NSURLSessionTask.

NSUUID

The NSUUID class creates UUID strings that are to uniquely identify types, interfaces, and other items.

NSUbiquitousKeyValueStore

Use the iCloud key-value store to make preference, configuration, and app-state data available to every instance of your app on every device connected to a user’s iCloud account.

NSUndoManager

NSUndoManager is a general-purpose recorder of operations for undo and redo.

NSUserActivity

An NSUserActivity object encapsulates the state of a user activity in an application on a particular device in a way that allows the same activity to be continued on another device in a corresponding application from the same developer.

NSUserDefaults

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system.

NSValue

An NSValue object is a simple container for a single C or Objective-C data item.

NSNumber

NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type.

NSDecimalNumber

NSDecimalNumber, an immutable subclass of NSNumber, provides an object-oriented wrapper for doing base-10 arithmetic.

NSValueTransformer

NSValueTransformer is an abstract class that is used by the Cocoa Bindings technology to transform values from one representation to another.

NSXMLParser

Instances of this class parse XML documents (including DTD declarations) in an event-driven manner.

NSProxy

NSProxy is an abstract superclass defining an API for objects that act as stand-ins for other objects or for objects that don’t exist yet.

Protocols

NSCacheDelegate

The delegate of an NSCache object implements this protocol to perform specialized actions when an object is about to be evicted or removed from the cache.

NSCoding

The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded.

NSCopying

The NSCopying protocol declares a method for providing functional copies of an object.

NSDecimalNumberBehaviors

The NSDecimalBehaviors protocol declares three methods that control the discretionary aspects of working with NSDecimalNumber objects.

NSDiscardableContent

You implement this protocol when a class’s objects have subcomponents that can be discarded when not being used, thereby giving an application a smaller memory footprint.

NSErrorRecoveryAttempting

The NSErrorRecoveryAttempting informal protocol provides methods that allow your application to attempt to recover from an error.

NSExtensionRequestHandling

The NSExtensionRequestHandling protocol provides a life cycle hook into an app extension.

NSFastEnumeration

The fast enumeration protocol NSFastEnumeration must be adopted and implemented by objects used in conjunction with the for language construct used in conjunction with Cocoa objects.

NSFileManagerDelegate

The NSFileManagerDelegate protocol defines optional methods for managing operations involving the copying, moving, linking, or removal of files and directories.

NSFilePresenter

The NSFilePresenter protocol should be implemented by objects that allow the user to view or edit the content of files or directories.

NSKeyValueCoding

The NSKeyValueCoding informal protocol defines a mechanism by which you can access the properties of an object indirectly by name (or key), rather than directly through invocation of an accessor method or as instance variables.

NSKeyValueObserving

The NSKeyValueObserving (KVO) informal protocol defines a mechanism that allows objects to be notified of changes to the specified properties of other objects.

NSKeyedArchiverDelegate

The NSKeyedArchiverDelegate protocol defines the optional methods implemented by delegates of NSKeyedArchiver objects.

NSKeyedUnarchiverDelegate

The NSKeyedUnarchiverDelegate protocol defines the optional methods implemented by delegates of NSKeyedUnarchiver objects.

NSLocking

The NSLocking protocol declares the elementary methods adopted by classes that define lock objects.

NSMachPortDelegate

The NSMachPortDelegate protocol defines the optional methods implemented by delegates of NSMachPort objects.

NSMetadataQueryDelegate

The NSMetadataQueryDelegate protocol defines the optional methods implemented by delegates of NSMetadataQuery objects.

NSMutableCopying

The NSMutableCopying protocol declares a method for providing mutable copies of an object.

NSNetServiceBrowserDelegate

The NSNetServiceBrowserDelegate protocol defines the optional methods implemented by delegates of NSNetServiceBrowser objects.

NSNetServiceDelegate

The NSNetServiceDelegate protocol defines the optional methods implemented by delegates of NSNetService objects.

NSObject

The NSObject protocol groups methods that are fundamental to all Objective-C objects.

NSPortDelegate

The NSPortDelegate protocol defines the optional methods implemented by delegates of NSPort objects.

NSSecureCoding

Conforming to the NSSecureCoding protocol indicates that an object handles encoding and decoding instances of itself in a manner that is robust against object substitution attacks.

NSStreamDelegate

The NSStreamDelegate protocol defines the optional methods implemented by delegates of NSStream objects.

NSURLAuthenticationChallengeSender

The NSURLAuthenticationChallengeSender protocol represents the interface that the sender of an authentication challenge must implement.

NSURLConnectionDataDelegate

The NSURLConnectionDataDelegate protocol describes methods that should be implemented by the delegate for an instance of the NSURLConnection class.

NSURLConnectionDelegate

The NSURLConnectionDelegate protocol defines methods common to the NSURLConnectionDataDelegate and NSURLConnectionDownloadDelegate protocols.

NSURLConnectionDownloadDelegate

The NSURLConnectionDownloadDelegate protocol describes methods that should be implemented by the delegate of instances of NSURLConnection created using Newsstand Kit’s downloadWithDelegate: method.

NSURLProtocolClient

The NSURLProtocolClient protocol provides the interface used by NSURLProtocol subclasses to communicate with the URL loading system.

NSURLSessionDataDelegate

The NSURLSessionDataDelegate protocol defines the methods that a delegate of an NSURLSession object can implement to handle task-level events specific to data tasks and upload tasks.

NSURLSessionDelegate

The NSURLSessionDelegate protocol describes the methods that NSURLSession objects call on their delegates to handle session-level events.

NSURLSessionDownloadDelegate

The NSURLSessionDownloadDelegate protocol defines delegate methods that you should implement when using NSURLSession download tasks.

NSURLSessionTaskDelegate

The NSURLSessionTaskDelegate protocol defines the task-specific delegate methods that you should implement when working with any type of NSURLSession task.

NSUserActivityDelegate

An object conforming to the NSUserActivityDelegate protocol works with an NSUserActivity object, which encapsulates the state of a user activity in an application on a particular device and enables the same activity to be continued on another device.

NSXMLParserDelegate

The NSXMLParserDelegate protocol defines the optional methods implemented by delegates of NSXMLParser objects.

Other Reference

Foundation Functions Reference

Foundation Constants Reference

Foundation Data Types Reference