Value object

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 NSString, NSDate, and 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 char, NSTimeInterval, int, float, or double):


NSValue provides a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as char, int, float, or double, as well as pointers, structures, and object IDs. It lets you add items of such data types to collections such as instances of NSArray and NSSet, which require their elements to be objects. This is particularly useful if you need to put point, size, or rectangle structures (such as NSPoint, CGSize, or NSRect) into a collection.

Prerequisite Articles