Up

NSValue class reference

Authors

Adam Fedor (fedor@boulder.colorado.edu)
Richard frith-Macdonald (rfm@gnu.org)

Version: 1.32

Date: 2003/07/31 23:49:32

Copyright: (C) 1993, 1994, 1996, 1999 Free Software Foundation, Inc.


Contents -

  1. Software documentation for the NSNumber class
  2. Software documentation for the NSValue class
  3. Software documentation for the NSNumber(GSCategories) category
  4. Software documentation for the NSValue(Subclassing) category

Software documentation for the NSNumber class

NSNumber : NSValue

Declared in:
Foundation/NSValue.h
Conforms to:
NSCopying
NSCoding
Standards:

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.

Method summary

numberWithBool: 

+ (NSNumber*) numberWithBool: (BOOL)value;

New instance from boolean value.


numberWithChar: 

+ (NSNumber*) numberWithChar: (signed char)value;

New instance from signed char value.


numberWithDouble: 

+ (NSNumber*) numberWithDouble: (double)value;

New instance from double value.


numberWithFloat: 

+ (NSNumber*) numberWithFloat: (float)value;

New instance from float value.


numberWithInt: 

+ (NSNumber*) numberWithInt: (signed int)value;

New instance from (signed) int value.


numberWithLong: 

+ (NSNumber*) numberWithLong: (signed long)value;

New instance from (signed) long value.


numberWithLongLong: 

+ (NSNumber*) numberWithLongLong: (signed long long)value;

New instance from (signed) long long value.


numberWithShort: 

+ (NSNumber*) numberWithShort: (signed short)value;

New instance from (signed) short value.


numberWithUnsignedChar: 

+ (NSNumber*) numberWithUnsignedChar: (unsigned char)value;

New instance from unsigned char value.


numberWithUnsignedInt: 

+ (NSNumber*) numberWithUnsignedInt: (unsigned int)value;

New instance from unsigned int value.


numberWithUnsignedLong: 

+ (NSNumber*) numberWithUnsignedLong: (unsigned long)value;

New instance from unsigned long value.


numberWithUnsignedLongLong: 

+ (NSNumber*) numberWithUnsignedLongLong: (unsigned long long)value;

New instance from unsigned long long value.


numberWithUnsignedShort: 

+ (NSNumber*) numberWithUnsignedShort: (unsigned short)value;

New instance from unsigned short value.


boolValue 

- (BOOL) 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 

- (signed char) charValue;

Returns value as a signed char, converting if necessary.


compare: 

- (NSComparisonResult) compare: (NSNumber*)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 

- (NSString*) description;

Returns the string representation of this number using a non-localised conversion (decimal point is '.' irrespective of the locale).


descriptionWithLocale: 

- (NSString*) descriptionWithLocale: (NSDictionary*)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 

- (double) doubleValue;

Returns value as a double, converting if necessary.


floatValue 

- (float) floatValue;

Returns value as a float, converting if necessary.


initWithBool: 

- (id) initWithBool: (BOOL)value;

Initialize from boolean value.


initWithChar: 

- (id) initWithChar: (signed char)value;

Initialize from signed char value.


initWithDouble: 

- (id) initWithDouble: (double)value;

Initialize from double value.


initWithFloat: 

- (id) initWithFloat: (float)value;

Initialize from float value.


initWithInt: 

- (id) initWithInt: (signed int)value;

Initialize from (signed) int value.


initWithLong: 

- (id) initWithLong: (signed long)value;

Initialize from (signed) long value.


initWithLongLong: 

- (id) initWithLongLong: (signed long long)value;

Initialize from (signed) long long value.


initWithShort: 

- (id) initWithShort: (signed short)value;

Initialize from (signed) short value.


initWithUnsignedChar: 

- (id) initWithUnsignedChar: (unsigned char)value;

Initialize from unsigned char value.


initWithUnsignedInt: 

- (id) initWithUnsignedInt: (unsigned int)value;

Initialize from unsigned int value.


initWithUnsignedLong: 

- (id) initWithUnsignedLong: (unsigned long)value;

Initialize from unsigned long value.


initWithUnsignedLongLong: 

- (id) initWithUnsignedLongLong: (unsigned long long)value;

Initialize from unsigned long long value.


initWithUnsignedShort: 

- (id) initWithUnsignedShort: (unsigned short)value;

Initialize from unsigned short value.


intValue 

- (signed int) intValue;

Returns value as a (signed) int, converting if necessary.


isEqualToNumber: 

- (BOOL) isEqualToNumber: (NSNumber*)otherNumber;

Returns whether receiver and otherNumber represent the same numerical value.


longLongValue 

- (signed long long) longLongValue;

Returns value as a (signed) long long, converting if necessary.


longValue 

- (signed long) longValue;

Returns value as a (signed) long, converting if necessary.


shortValue 

- (signed short) shortValue;

Returns value as a (signed) short, converting if necessary.


stringValue 

- (NSString*) stringValue;

Returns -description .


unsignedCharValue 

- (unsigned char) unsignedCharValue;

Returns value as an unsigned char, converting if necessary.


unsignedIntValue 

- (unsigned int) unsignedIntValue;

Returns value as an unsigned int, converting if necessary.


unsignedLongLongValue 

- (unsigned long long) unsignedLongLongValue;

Returns value as an unsigned long long, converting if necessary.


unsignedLongValue 

- (unsigned long) unsignedLongValue;

Returns value as an unsigned long, converting if necessary.


unsignedShortValue 

- (unsigned short) unsignedShortValue;

Returns value as an unsigned short, converting if necessary.


Software documentation for the NSValue class

NSValue : NSObject

Declared in:
Foundation/NSValue.h
Conforms to:
NSCopying
NSCoding
Standards:

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.

Method summary

value: withObjCType: 

+ (NSValue*) value: (const void*)value withObjCType: (const char*)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: objCType: 

+ (NSValue*) valueWithBytes: (const void*)value objCType: (const char*)type;

Synonym for value:withObjCType:.


valueWithNonretainedObject: 

+ (NSValue*) valueWithNonretainedObject: (id)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: 

+ (NSValue*) valueWithPoint: (NSPoint)point;

Convenience method to create instance holding an NSPoint structure.


valueWithPointer: 

+ (NSValue*) valueWithPointer: (const void*)pointer;

Convenience method to create instance holding a pointer. Same as using @encode(void *) in +value:withObjCType: .


valueWithRange: 

+ (NSValue*) valueWithRange: (NSRange)range;

Convenience method to create instance holding an NSRange structure.


valueWithRect: 

+ (NSValue*) valueWithRect: (NSRect)rect;

Convenience method to create instance holding an NSRect structure.


valueWithSize: 

+ (NSValue*) valueWithSize: (NSSize)size;

Convenience method to create instance holding an NSSize structure.


getValue: 

- (void) getValue: (void*)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: objCType: 

- (id) initWithBytes: (const void*)data objCType: (const char*)type;
This is a designated initialiser for the class.

Initialize with value of type, parallel to value:withObjCType:.


isEqualToValue: 

- (BOOL) isEqualToValue: (NSValue*)other;

Compares this instance to another NSValue. For equality, both contents and declared type of the two values must match.


nonretainedObjectValue 

- (id) nonretainedObjectValue;

If receiver was initialized with an object ID, return it, else raises NSInternalInconsistencyException.


objCType 

- (const char*) objCType;

Returns the string @encode(...) compatible type the receiver was initialized with.


pointValue 

- (NSPoint) pointValue;

If receiver was initialized with an NSPoint value, return it, else raises NSInternalInconsistencyException.


pointerValue 

- (void*) pointerValue;

If receiver was initialized with a void * pointer, return it, else raises NSInternalInconsistencyException.


rangeValue 

- (NSRange) rangeValue;

If receiver was initialized with an NSRange value, return it, else raises NSInternalInconsistencyException.


rectValue 

- (NSRect) rectValue;

If receiver was initialized with an NSRect value, return it, else raises NSInternalInconsistencyException.


sizeValue 

- (NSSize) sizeValue;

If receiver was initialized with an NSSize value, return it, else raises NSInternalInconsistencyException.


Software documentation for the NSNumber(GSCategories) category

NSNumber(GSCategories)

Declared in:
Foundation/NSValue.h
Standards:

GNUstep specific (non-standard) additions to the NSNumber class.

Method summary

valueFromString: 

+ (NSValue*) valueFromString: (NSString*)string;

Parses string as a double, int, or unsigned int depending on what characters are present. Uses atof and atoi which don't report errors, so be careful if the string might contain an invalid value.


Software documentation for the NSValue(Subclassing) category

NSValue(Subclassing)

Declared in:
Foundation/NSValue.h
Standards:

Note: Defines a method that is not in the OpenStep spec, but makes subclassing easier.

Method summary

valueClassWithObjCType: 

+ (Class) valueClassWithObjCType: (const char*)type;

Used by value: withObjCType: to determine the concrete subclass to alloc.



Up