Data
The Foundation framework provides many classes and protocols that extend the capabilities of the Objective-C language to represent and work with basic data types, such as strings and numbers, in an object-oriented fashion. Additionally, the Foundation framework provides application programming interfaces (APIs) for working with more complex data types, such as dates and collections.
Immutable Versus Mutable Classes
Classes such as NSString
and
NSArray
are
immutable
classes; instances of these classes
cannot be altered after they are initialized. Each immutable class,
however, has a
mutable
subclass:
for example, NSString
has the mutable subclass
NSMutableString
, and NSArray
has the subclass NSMutableArray
. Mutable
subclasses extend their superclass’s functionality
to allow modification after initialization. Immutable classes are
more efficient, but mutable classes are more flexible.
Basic Types
Two of the most basic data types
in an application are strings and
numbers
. The
Foundation framework provides object abstractions in the form of
NSString
and NSNumber
, and an
extensive API to manipulate them.
Strings
Foundation’s primary class used to represent and
manipulate strings is NSString
. Instances of
NSString
can be considered, at their core, an
immutable array of Unicode characters, and can represent characters
from the alphabets of nearly every written language, past and
present. In fact, NSString
is a class cluster, which shields the developer from a number of underlying ...
Get Cocoa in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.