A value object is in essence an object-oriented wrapper for a simple data element such as a string, number, or date. The common value classes in Cocoa are
NSNumber. Value objects are often attributes of other custom objects you create.
Value objects offer richer behavior than the corresponding simple scalar types (such as
You can put any of the value objects in a collection, such as an instance of
NSString, and its subclass
NSMutableString, you can perform a wide range of string-related operations. For example, you can join strings together, split strings apart, work on file paths, transform the case of characters, and search for substrings. In all of these, string objects are treated as Unicode.
NSDate, in conjunction with
NSCalendarand other related classes, you can perform complicated calendrical calculations such as determining the number of months and days between two instants in time based on the user’s preferred calendar, taking into account variables such as time zones and leap years.
NSDecimalNumber, you can accurately perform currency-based calculations.
NSValue provides a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as
double, as well as pointers, structures, and object IDs. It lets you add items of such data types to collections such as instances of
NSSet, which require their elements to be objects. This is particularly useful if you need to put point, size, or rectangle structures (such as
NSRect) into a collection.