Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.

NSValue

Inherits From: NSObject

Conforms To: NSCoding, NSCopying NSObject (NSObject)

Declared In: Foundation/NSValue.h

Foundation/NSGeometry.h

Class Description

NSValue objects provide an object-oriented wrapper for the data types defined in standard C and Objective C. The NSValue class is often used to put Objective C and standard C data types into collections that require objects, such as NSArray objects. When a value object is instantiated, it is encoded with the specified data type.

The NSValue class declares the programmatic interface to an object that contains a C data type. It provides methods for creating value objects that contain values of a specified data type, pointers, and other objects.

Use NSValue objects to put C types into collections. Use NSNumber objects to put numbers into collections.

The following code puts an NSRange into an NSArray, using the Objective C @encode directive to get a character string that encodes the type structure of NSRange:

[myArray insertObject:[NSValue value:&range withObjCType:@encode(NSRange)] atIndex:n]

To get the value back, you would do this:

[[myArray objectAtIndex:n] getValue:&range]

NSValue objects are provided with generic coding and copying behavior. To subclass NSValue and preserve class when encoding or copying, override classForCoder, initWithCoder:, encodeWithCoder: (for encoding), and copyWithZone: (for copying).

General Exception Conditions

NSValue can raise NSInternalInconsistencyException in a variety of cases where an unkown Objective C type is found. In addition, NSValue's implementation of encodeWithCoder: can raise NSInvalidArgumentException if an attempt is made to encode void.

Allocating and Initializing Value Objects

Allocating and Initializing Geometry Value Objects

Accessing Data in Value Objects

Accessing Data in Value Geometry Objects