Inherits From:
NSValue : NSObject
Conforms To:
NSCoding (NSValue)
NSCopying (NSValue)
NSObject (NSObject)
Declared In:
Foundation/NSValue.h
Foundation/NSDecimalNumber.h
+ numberWithType: | Returns an initialized NSNumber of the specified type. |
- typeValue | Returns the value of an NSNumber as a specific numeric type. |
- compare: | Compares two NSNumbers. |
char
, short
int
, int
, long int
, long long int
, float
, or double
, or as a BOOL. It also defines a compare:
method to determine the ordering of two NSNumber objects.An NSNumber records the numeric type it's created with, and uses the C rules for numeric conversion when comparing NSNumbers of different numeric types and when returning values as C numeric types. See any standard C reference for information on type conversion.
objCType
can return, in order to take advantage of the abstract implementations of the non-primitive methods. The valid return values are "c", "C", "s", "S", "i", "I", "l", "L", "q", "Q", "f", and "d".numberWithBool:
(BOOL)value
Creates and returns an NSNumber containing value, treating it as a BOOL.
numberWithChar:
(char)value
Creates and returns an NSNumber containing value, treating it as a signed
char
.
numberWithDouble:
(double)value
Creates and returns an NSNumber containing value, treating it as a double
.
numberWithFloat:
(float)value
Creates and returns an NSNumber containing value, treating it as a float
.
numberWithInt:
(int)value
Creates and returns an NSNumber containing value, treating it as a signed
int
.
numberWithLong:
(long int)value
Creates and returns an NSNumber containing value, treating it as a signed
long int
.
numberWithLongLong:
(long long int)value
Creates and returns an NSNumber containing value, treating it as a signed
long long int
.
numberWithShort:
(short int)value
Creates and returns an NSNumber containing value, treating it as a signed
short int
.
numberWithUnsignedChar:
(unsigned char)value
Creates and returns an NSNumber containing value, treating it as an unsigned char
.
numberWithUnsignedInt:
(unsigned int)value
Creates and returns an NSNumber containing value, treating it as an unsigned int
.
numberWithUnsignedLong:
(unsigned long int)value
Creates and returns an NSNumber containing value, treating it as an unsigned long int
.
numberWithUnsignedLongLong:
(unsigned long long int)value
Creates and returns an NSNumber containing value, treating it as an unsigned long long int
.
numberWithUnsignedShort:
(unsigned short int)value
Creates and returns an NSNumber containing value, treating it as an unsigned short int
.
boolValue
Returns the receiver's value as a BOOL, converting it as necessary.
charValue
Returns the receiver's value as a char, converting it as necessary.
compare:
(NSNumber *)aNumber
Returns NSOrderedAscending if
aNumber's value is greater than the receiver's, NSOrderedSame if they're equal, and NSOrderedDescending if aNumber's value is less than the receiver's.
compare: follows the standard C rules for type conversion. For example, if you compare an NSNumber that has an integer value with an NSNumber that has a floating point value, the integer value is converted to a floating point value for comparison.
(NSDecimal)decimalValue
Returns the receiver's value, expressed as an NSDecimal struct. The value returned isn't guaranteed to be exact for float and double values.
(NSString *)description
Overrides the NSObject description
method to invoke descriptionWithLocale:
. In other words, instead printing the name of the receiver's class and the hexadecimal value of its id
like the NSObject implementation, returns a string representation of the receiver's value.
descriptionWithLocale:
(NSDictionary *)aLocale
Returns an NSString that represents the contents of the receiver. For example, if you have an NSNumber that has the integer value 522, sending it the descriptionWithLocale:
message returns the string "522". aLocale specifies options used for formatting the description; use nil
if you don't want the description formatted.
To obtain the string representation, this method invokes NSString's initWithFormat:locale:
method, supplying the format based on the type the NSNumber was created with:
Data Type | Format Specification |
---|---|
char | %i |
double | %0.16g |
float | %0.7g |
int | %i |
long | %li |
long long | %li |
short | %hi |
unsigned char | %u |
unsigned int | %u |
unsigned long | %lu |
unsigned long long | %lu |
unsigned short | %hu |
See also:
- stringValue
doubleValue
Returns the receiver's value as a double, converting it as necessary.
floatValue
Returns the receiver's value as a float, converting it as necessary.
initWithBool:
(BOOL)value
Initializes a newly allocated NSNumber to contain value, treated as a BOOL.
initWithChar:
(char)value
Initializes a newly allocated NSNumber to contain value, treated as a signed
char
.
initWithDouble:
(double)value
Initializes a newly allocated NSNumber to contain value, treated as a double
.
initWithFloat:
(float)value
Initializes a newly allocated NSNumber to contain value, treated as a float
.
initWithInt:
(int)value
Initializes a newly allocated NSNumber to contain value, treated as a signed
int
.
initWithLong:
(long int)value
Initializes a newly allocated NSNumber to contain value, treated as a signed
long int
.
initWithLongLong:
(long long int)value
Initializes a newly allocated NSNumber to contain value, treated as a signed
long long int
.
initWithShort:
(short int)value
Initializes a newly allocated NSNumber to contain value, treated as a signed
short int
.
initWithUnsignedChar:
(unsigned char)value
Initializes a newly allocated NSNumber to contain value, treated as an unsigned char
.
initWithUnsignedInt:
(unsigned int)value
Initializes a newly allocated NSNumber to contain value, treated as an unsigned int
.
initWithUnsignedLong:
(unsigned long int)value
Initializes a newly allocated NSNumber to contain value, treated as an unsigned long int
.
initWithUnsignedLongLong:
(unsigned long long int)value
Initializes a newly allocated NSNumber to contain value, treated as an unsigned long long int
.
initWithUnsignedShort:
(unsigned short int)value
Initializes a newly allocated NSNumber to contain value, treated as an unsigned short int
.
intValue
Returns the receiver's value as an int, converting it as necessary.
isEqualToNumber:
(NSNumber *)aNumber
Returns YES if the receiver and aNumber are equal, otherwise returns NO. Two NSNumbers are considered equal if they have the same id
s or if they have equivalent values (as determined by the compare:
method).
longLongValue
Returns the receiver's value as a long long int, converting it as necessary.
longValue
Returns the receiver's value as a long int, converting it as necessary.
shortValue
Returns the receiver's value as a short int, converting it as necessary.
stringValue
Returns the receiver's value as a human-readable NSString, by invoking descriptionWithLocale:
where locale is nil.
unsignedCharValue
Returns the receiver's value as an unsigned char, converting it as necessary.
unsignedIntValue
Returns the receiver's value as an unsigned int, converting it as necessary.
unsignedLongLongValue
Returns the receiver's value as an unsigned long long int, converting it as necessary.
unsignedLongValue
Returns the receiver's value as an unsigned long int, converting it as necessary.
unsignedShortValue
Returns the receiver's value as an unsigned short int, converting it as necessary.
Copyright © 1997, Apple Computer, Inc. All rights reserved.