| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in Mac OS X v10.0 and later. |
| Companion guide | |
| Declared in | NSGeometry.h NSRange.h NSValue.h |
| Related sample code |
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.
– initWithBytes:objCType:
+ valueWithBytes:objCType:
+ value:withObjCType:
+ valueWithNonretainedObject:
+ valueWithPointer:
+ valueWithPoint:
+ valueWithRange:
+ valueWithRect:
+ valueWithSize:
– getValue:
– nonretainedObjectValue
– objCType
– pointValue
– pointerValue
– rangeValue
– rectValue
– sizeValue
Creates and returns an NSValue object that contains a given value which is interpreted as being of a given Objective-C type.
+ (NSValue *)value:(const void *)value withObjCType:(const char *)type
The value for the new NSValue object.
The Objective-C type of value. type should be created with the Objective-C @encode() compiler directive; it should not be hard-coded as a C string.
A new NSValue object that contains value, which is interpreted as being of the Objective-C type type.
This method has the same effect as valueWithBytes:objCType: and may be deprecated in a future release. You should use valueWithBytes:objCType: instead.
NSValue.hCreates and returns an NSValue object that contains a given value, which is interpreted as being of a given Objective-C type.
+ (NSValue *)valueWithBytes:(const void *)value objCType:(const char *)type
The value for the new NSValue object.
The Objective-C type of value. type should be created with the Objective-C @encode() compiler directive; it should not be hard-coded as a C string.
A new NSValue object that contains value, which is interpreted as being of the Objective-C type type.
See Number and Value Programming Topics for Cocoa for other considerations in creating an NSValue object and code examples.
NSValue.hCreates and returns an NSValue object that contains a given object.
+ (NSValue *)valueWithNonretainedObject:(id)anObject
The value for the new object.
A new NSValue object that contains anObject.
This method is equivalent to invoking value:withObjCType: in this manner:
NSValue *theValue = [NSValue value:&anObject withObjCType:@encode(void *)]; |
This method is useful for preventing an object from being retained when it’s added to a collection object (such as an instance of NSArray or NSDictionary).
NSValue.h
Creates and returns an NSValue object that contains a given NSPoint structure.
+ (NSValue *)valueWithPoint:(NSPoint)aPoint
The value for the new object.
A new NSValue object that contains the value of point.
NSGeometry.h
Creates and returns an NSValue object that contains a given pointer.
+ (NSValue *)valueWithPointer:(const void *)aPointer
The value for the new object.
A new NSValue object that contains aPointer.
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.
NSValue.h
Creates and returns an NSValue object that contains a given NSRange structure.
+ (NSValue *)valueWithRange:(NSRange)range
The value for the new object.
A new NSValue object that contains the value of range.
NSRange.h
Creates and returns an NSValue object that contains a given NSRect structure.
+ (NSValue *)valueWithRect:(NSRect)rect
The value for the new object.
A new NSValue object that contains the value of rect.
NSGeometry.h
Creates and returns an NSValue object that contains a given NSSize structure.
+ (NSValue *)valueWithSize:(NSSize)size
The value for the new object.
A new NSValue object that contains the value of size.
NSGeometry.hCopies the receiver’s value into a given buffer.
- (void)getValue:(void *)buffer
A buffer into which to copy the receiver's value. buffer must be large enough to hold the value.
NSValue.h
Initializes and returns an NSValue object that contains a given value, which is interpreted as being of a given Objective-C type.
- (id)initWithBytes:(const void *)value objCType:(const char *)type
The value for the new NSValue object.
The Objective-C type of value. type should be created with the Objective-C @encode() compiler directive; it should not be hard-coded as a C string.
An initialized NSValue object that contains value, which is interpreted as being of the Objective-C type type. The returned object might be different than the original receiver.
See Number and Value Programming Topics for Cocoa for other considerations in creating an NSValue object.
This is the designated initializer for the NSValue class.
NSValue.h
Returns a Boolean value that indicates whether the receiver and another value are equal.
- (BOOL)isEqualToValue:(NSValue *)value
The value with which to compare the receiver.
YES if the receiver and aValue are equal, otherwise NO. For NSValue objects, the class, type, and contents are compared to determine equality.
NSValue.h
Returns the receiver's value as an id.
- (id)nonretainedObjectValue
The receiver's value as an id. If the receiver was not created to hold a pointer-sized data item, the result is undefined.
NSValue.hReturns a C string containing the Objective-C type of the data contained in the receiver.
- (const char *)objCType
A C string containing the Objective-C type of the data contained in the receiver, as encoded by the @encode() compiler directive.
NSValue.h
Returns the receiver's value as a pointer to void.
- (void *)pointerValue
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.
NSValue.h
Returns an NSPoint structure representation of the receiver.
- (NSPoint)pointValue
An NSPoint structure representation of the receiver.
NSGeometry.hReturns an NSRange structure representation of the receiver.
- (NSRange)rangeValue
An NSRange structure representation of the receiver.
NSRange.hReturns an NSRect structure representation of the receiver.
- (NSRect)rectValue
An NSRect structure representation of the receiver.
NSGeometry.hReturns an NSSize structure representation of the receiver.
- (NSSize)sizeValue
An NSSize structure representation of the receiver.
NSGeometry.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)