Class: NSValue

Inherits:
NSObject show all

Overview

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.

Direct Known Subclasses

NSNumber

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (NSValue) value(value, withObjCType:type)

Creates and returns an NSValue object that contains a given value which is interpreted as being of a given Objective-C type. This method has the same effect as valueWithBytes:objCType: and may be deprecated in a future release. You should use valueWithBytes:objCType: instead.

Parameters:

  • value (Object)

    The value for the new NSValue object.

  • type (const char)

    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.

Returns:

  • (NSValue)

    A new NSValue object that contains value, which is interpreted as being of the Objective-C type type.

+ (NSValue) valueWithBytes(value, objCType:type)

Creates and returns an NSValue object that contains a given value, which is interpreted as being of a given Objective-C type. See Number and Value Programming Topics for other considerations in creating an NSValue object and code examples.

Parameters:

  • value (Object)

    The value for the new NSValue object.

  • type (const char)

    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.

Returns:

  • (NSValue)

    A new NSValue object that contains value, which is interpreted as being of the Objective-C type type.

+ (NSValue) valueWithNonretainedObject(anObject)

Creates and returns an NSValue object that contains a given object.

This method is equivalent to invoking value:withObjCType: in this manner:This method is useful if you want to add an object to a collection but don’t want the collection to create a strong reference to it.

Parameters:

  • anObject (Object)

    The value for the new object.

Returns:

+ (NSValue) valueWithPointer(aPointer)

Creates and returns an NSValue object that contains a given pointer. This method is equivalent to invoking value:withObjCType: in this manner:This method does not copy the contents of aPointer, so you must not to free the memory at the pointer destination while the NSValue object exists. NSData objects may be more suited for arbitrary pointers than NSValue objects.

Parameters:

  • aPointer (Object)

    The value for the new object.

Returns:

+ (NSValue) valueWithRange(range)

Creates and returns an NSValue object that contains a given NSRange structure.

Parameters:

  • range (NSRange)

    The value for the new object.

Returns:

  • (NSValue)

    A new NSValue object that contains the value of range.

Instance Method Details

- (Object) getValue(buffer)

Copies the receiver’s value into a given buffer.

Parameters:

  • buffer (Object)

    A buffer into which to copy the receiver’s value. buffer must be large enough to hold the value.

Returns:

- (Object) initWithBytes(value, objCType:type)

Initializes and returns an NSValue object that contains a given value, which is interpreted as being of a given Objective-C type. See Number and Value Programming Topics for other considerations in creating an NSValue object.This is the designated initializer for the NSValue class.

Parameters:

  • value (Object)

    The value for the new NSValue object.

  • type (const char)

    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.

Returns:

  • (Object)

    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.

- (Boolean) isEqualToValue(value)

Returns a Boolean value that indicates whether the receiver and another value are equal.

Parameters:

  • aValue (NSValue)

    The value with which to compare the receiver.

Returns:

  • (Boolean)

    YES if the receiver and aValue are equal, otherwise NO. For NSValue objects, the class, type, and contents are compared to determine equality.

- (Object) nonretainedObjectValue

Returns the receiver's value as an id.

Returns:

  • (Object)

    The receiver's value as an id. If the receiver was not created to hold a pointer-sized data item, the result is undefined.

- (const char) objCType

Returns a C string containing the Objective-C type of the data contained in the receiver.

Returns:

  • (const char)

    A C string containing the Objective-C type of the data contained in the receiver, as encoded by the @encode() compiler directive.

- (Object) pointerValue

Returns the receiver's value as a pointer to void.

Returns:

  • (Object)

    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.

- (NSRange) rangeValue

Returns an NSRange structure representation of the receiver.

Returns: