# NSValue class reference

fedor@boulder.colorado.edu
rfm@gnu.org
Generated at 2025-12-02 21:52:00 +0000
1993, 1994, 1996, 1999 Free Software Foundation, Inc.
Software documentation for the NSNumber class
Foundation/NSValue.h
NSCopying
NSCoding
Subclass of NSValue offering convenience methods for initializing from and accessing as any C primitive numeric type. On access, the value will be type-converted if necessary, using standard C conversion rules.
numberWithBool:
value
New instance from boolean value.
numberWithChar:
value
New instance from signed char value.
numberWithDouble:
value
New instance from double value.
numberWithFloat:
value
New instance from float value.
numberWithInt:
value
New instance from (signed) int value.
numberWithInteger:
value
Return a number intialised with NSInteger.
numberWithLong:
value
New instance from (signed) long value.
numberWithLongLong:
value
New instance from (signed) long long value.
numberWithShort:
value
New instance from (signed) short value.
numberWithUnsignedChar:
value
New instance from unsigned char value.
numberWithUnsignedInt:
value
New instance from unsigned int value.
numberWithUnsignedInteger:
value
Return a number intialised with NSUInteger.
numberWithUnsignedLong:
value
New instance from unsigned long value.
numberWithUnsignedLongLong:
value
New instance from unsigned long long value.
numberWithUnsignedShort:
value
New instance from unsigned short value.
boolValue
Return value as a BOOL; this will in fact be a char value converted if necessary from type initialized with; if you wish to consider anything nonzero TRUE do not compare directly to `YES`, but use `'!= NO'`.
charValue
Returns value as a signed char, converting if necessary.
compare:
otherNumber
Compares receiver with otherNumber, using C type conversion if necessary, and returns `NSOrderedAscending`, `NSOrderedDescending`, or `NSOrderedSame` depending on whether it is less than, greater than, or equal to otherNumber.
description
Returns the string representation of this number using a non-localised conversion (decimal point is '.' irrespective of the locale).
descriptionWithLocale:
locale

Produces a string representation of the number. For a boolean this will be either 'true' or 'false'. For other numbers the format is produced using the initWithFormat:locale:... method of NSString, and the format depends on the type of number as follows -

char
%i
short
%hi
int
%i
long
%li
long long
%lli
unsigned char
%u
unsigned short
%hu
unsigned int
%u
unsigned long
%lu
unsigned long long
%llu
float
%0.7g
double
%0.16g
doubleValue
Returns value as a double, converting if necessary.
floatValue
Returns value as a float, converting if necessary.
initWithBool:
value
Initialize from boolean value.
initWithChar:
value
Initialize from signed char value.
initWithDouble:
value
Initialize from double value.
initWithFloat:
value
Initialize from float value.
initWithInt:
value
Initialize from (signed) int value.
initWithInteger:
value
Initialise the receiver with NSInteger content.
initWithLong:
value
Initialize from (signed) long value.
initWithLongLong:
value
Initialize from (signed) long long value.
initWithShort:
value
Initialize from (signed) short value.
initWithUnsignedChar:
value
Initialize from unsigned char value.
initWithUnsignedInt:
value
Initialize from unsigned int value.
initWithUnsignedInteger:
value
Initialise the receiver with NSUInteger content.
initWithUnsignedLong:
value
Initialize from unsigned long value.
initWithUnsignedLongLong:
value
Initialize from unsigned long long value.
initWithUnsignedShort:
value
Initialize from unsigned short value.
intValue
Returns value as a (signed) int, converting if necessary.
integerValue
Return the contents of the receiver as NSInteger.
isEqualToNumber:
otherNumber
Returns whether receiver and otherNumber represent the same numerical value.
longLongValue
Returns value as a (signed) long long, converting if necessary.
longValue
Returns value as a (signed) long, converting if necessary.
shortValue
Returns value as a (signed) short, converting if necessary.
stringValue
Returns -description .
unsignedCharValue
Returns value as an unsigned char, converting if necessary.
unsignedIntValue
Returns value as an unsigned int, converting if necessary.
unsignedIntegerValue
Return the contents of the receiver as NSUInteger.
unsignedLongLongValue
Returns value as an unsigned long long, converting if necessary.
unsignedLongValue
Returns value as an unsigned long, converting if necessary.
unsignedShortValue
Returns value as an unsigned short, converting if necessary.
Software documentation for the NSValue class
Foundation/NSValue.h
NSCopying
NSCoding
The `NSValue` class can wrap a single primitive value as an object so it can be used in the containers and other places where an object reference is needed. Once initialized, an `NSValue` is immutable, and there is no `NSMutableValue` class. You initialize it by giving it a pointer to the primitive value, and you should be careful this does not get freed until after the `NSValue` is no longer used.
value:
value
withObjCType:
type
Create new instance with specified value (a pointer) of given type, which is a string code obtainable through the compile-time operator `@encode(...)`. For example: NSValue *theValue = [NSValue value: &n withObjCType: @encode(int)];
valueWithBytes:
value
objCType:
type
Synonym for value:withObjCType:.
valueWithEdgeInsets:
insets
Convenience method to create instance holding an `NSEdgeInsets` structure.
valueWithNonretainedObject:
anObject
Create new instance holding anObject. This is useful if you want to add anObject to a collection such as NSArray but don't want it to be retained (a weak reference).
valueWithPoint:
point
Convenience method to create instance holding an `NSPoint` structure.
valueWithPointer:
pointer
Convenience method to create instance holding a pointer. Same as using `@encode(void *)` in +value:withObjCType: .
valueWithRange:
range
Convenience method to create instance holding an `NSRange` structure.
valueWithRect:
rect
Convenience method to create instance holding an `NSRect` structure.
valueWithSize:
size
Convenience method to create instance holding an `NSSize` structure.
edgeInsetsValue
If receiver was initialized with an `NSEdgeInsets` value, return it, else raises `NSInternalInconsistencyException` .
getValue:
value
Copies bytes from the pointer receiver was initialized with into buffer pointed to by value. Number of bytes copied is determined by the type. If type was a void * pointer or object id, the memory address itself is copied.
initWithBytes:
data
objCType:
type
Initialize with value of type, parallel to value:withObjCType:.
isEqualToValue:
other
Compares this instance to another `NSValue`. For equality, both contents and declared type of the two values must match.
nonretainedObjectValue
If receiver was initialized with an object ID, return it, else raises `NSInternalInconsistencyException`.
objCType
Returns the string `@encode(...)` compatible type the receiver was initialized with.
pointValue
If receiver was initialized with an `NSPoint` value, return it, else raises `NSInternalInconsistencyException`.
pointerValue
If receiver was initialized with a void * pointer, return it, else raises `NSInternalInconsistencyException`.
rangeValue
If receiver was initialized with an `NSRange` value, return it, else raises `NSInternalInconsistencyException`.
rectValue
If receiver was initialized with an `NSRect` value, return it, else raises `NSInternalInconsistencyException`.
sizeValue
If receiver was initialized with an `NSSize` value, return it, else raises `NSInternalInconsistencyException`.
Software documentation for the NSValue(Subclassing) category
Foundation/NSValue.h
Note: Defines a method that is not in the OpenStep spec, but makes subclassing easier.
valueClassWithObjCType:
type
Used by value: withObjCType: to determine the concrete subclass to alloc.