An NSValue
object is a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as int, float, and char, as well as pointers, structures, and object ids. The purpose of this class is to allow items of such data types to be added to collections such as instances of NSArray
and NSSet
, which require their elements to be objects. NSValue
objects are always immutable.
Adopted Protocols
Tasks
Creating an NSValue
Accessing Data
Comparing Objects
getValue:
Copies the receiver’s value into a given buffer.
- (void)getValue:(void *)buffer
Parameters
- buffer
-
A buffer into which to copy the receiver's value. buffer must be large enough to hold the value.
isEqualToValue:
Returns a Boolean value that indicates whether the receiver and another value are equal.
- (BOOL)isEqualToValue:(NSValue *)value
Parameters
- aValue
-
The value with which to compare the receiver.
Return Value
YES
if the receiver and aValue are equal, otherwise NO
. For NSValue
objects, the class, type, and contents are compared to determine equality.
pointerValue
Returns the receiver's value as a pointer to void.
- (void *)pointerValue
Return Value
The receiver's value as a pointer to void. If the receiver was not created to hold a pointer-sized data item, the result is undefined.
pointValue
Returns an NSPoint
structure representation of the receiver.
- (NSPoint)pointValue
Return Value
An NSPoint
structure representation of the receiver.
rangeValue
Returns an NSRange
structure representation of the receiver.
- (NSRange)rangeValue
Return Value
An NSRange
structure representation of the receiver.
rectValue
Returns an NSRect
structure representation of the receiver.
- (NSRect)rectValue
Return Value
An NSRect
structure representation of the receiver.
sizeValue
Returns an NSSize
structure representation of the receiver.
- (NSSize)sizeValue
Return Value
An NSSize
structure representation of the receiver.
valueWithPointer:
Creates and returns an NSValue
object that contains a given pointer.
+ (NSValue *)valueWithPointer:(const void *)aPointer
Parameters
- aPointer
-
The value for the new object.
Return Value
A new NSValue
object that contains aPointer.
Discussion
This method is equivalent to invoking value:withObjCType:
in this manner:
NSValue *theValue = [NSValue value:&aPointer withObjCType:@encode(void *)];
|
This method does not copy the contents of aPointer, so you must not to deallocate the memory at the pointer destination while the NSValue
object exists. NSData
objects may be more suited for arbitrary pointers than NSValue
objects.
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);