Class: NSData
Overview
NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects.
Direct Known Subclasses
Class Method Summary (collapse)
-
+ data
Creates and returns an empty data object.
-
+ dataWithBytes:length:
Creates and returns a data object containing a given number of bytes copied from a given buffer.
-
+ dataWithBytesNoCopy:length:
Creates and returns a data object that holds length bytes from the buffer bytes.
-
+ dataWithBytesNoCopy:length:freeWhenDone:
Creates and returns a data object that holds a given number of bytes from a given buffer.
-
+ dataWithContentsOfFile:
Creates and returns a data object by reading every byte from the file specified by a given path.
-
+ dataWithContentsOfFile:options:error:
Creates and returns a data object by reading every byte from the file specified by a given path.
-
+ dataWithContentsOfURL:
Returns a data object containing the data from the location specified by a given URL.
-
+ dataWithContentsOfURL:options:error:
Creates and returns a data object containing the data from the location specified by aURL.
-
+ dataWithData:
Creates and returns a data object containing the contents of another data object.
Instance Method Summary (collapse)
-
- bytes
Returns a pointer to the receiver’s contents.
-
- description
Returns an NSString object that contains a hexadecimal representation of the receiver’s contents.
-
- getBytes:length:
Copies a number of bytes from the start of the receiver's data into a given buffer.
-
- getBytes:range:
Copies a range of bytes from the receiver’s data into a given buffer.
-
- initWithBytes:length:
Returns a data object initialized by adding to it a given number of bytes of data copied from a given buffer.
-
- initWithBytesNoCopy:length:
Returns a data object initialized by adding to it a given number of bytes of data from a given buffer.
-
- initWithBytesNoCopy:length:freeWhenDone:
Initializes a newly allocated data object by adding to it length bytes of data from the buffer bytes.
-
- initWithContentsOfFile:
Returns a data object initialized by reading into it the data from the file specified by a given path.
-
- initWithContentsOfFile:options:error:
Returns a data object initialized by reading into it the data from the file specified by a given path.
-
- initWithContentsOfURL:
Initializes a newly allocated data object initialized with the data from the location specified by aURL.
-
- initWithContentsOfURL:options:error:
Returns a data object initialized with the data from the location specified by a given URL.
-
- initWithData:
Returns a data object initialized with the contents of another data object.
-
- isEqualToData:
Compares the receiving data object to otherData.
-
- length
Returns the number of bytes contained in the receiver.
-
- rangeOfData:options:range:
Finds and returns the range of the first occurrence of the given data, within the given range, subject to given options.
-
- subdataWithRange:
Returns a data object containing a copy of the receiver’s bytes that fall within the limits specified by a given range.
-
- to_str
returns a String object created using the receiver's internal storage.
-
- writeToFile:atomically:
Writes the bytes in the receiver to the file specified by a given path.
-
- writeToFile:options:error:
Writes the bytes in the receiver to the file specified by a given path.
-
- writeToURL:atomically:
Writes the bytes in the receiver to the location specified by aURL.
-
- writeToURL:options:error:
Writes the bytes in the receiver to the location specified by a given URL.
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
+ (Object) data
Creates and returns an empty data object. This method is declared primarily for the use of mutable subclasses of NSData.
+ (Object) dataWithBytes(bytes, length:length)
Creates and returns a data object containing a given number of bytes copied from a given buffer.
+ (Object) dataWithBytesNoCopy(bytes, length:length)
Creates and returns a data object that holds length bytes from the buffer bytes. The returned object takes ownership of the bytes pointer and frees it on deallocation. Therefore, bytes must point to a memory block allocated with malloc.
+ (Object) dataWithBytesNoCopy(bytes, length:length, freeWhenDone:freeWhenDone)
Creates and returns a data object that holds a given number of bytes from a given buffer.
+ (Object) dataWithContentsOfFile(path)
Creates and returns a data object by reading every byte from the file specified by a given path. This method is equivalent to dataWithContentsOfFile:options:error: with no options. If you need to know what was the reason for failure, use dataWithContentsOfFile:options:error:.A sample using this method can be found in “Working With Binary Data”.
+ (Object) dataWithContentsOfFile(path, options:mask, error:errorPtr)
Creates and returns a data object by reading every byte from the file specified by a given path.
+ (Object) dataWithContentsOfURL(aURL)
Returns a data object containing the data from the location specified by a given URL. If you need to know what was the reason for failure, use dataWithContentsOfURL:options:error:.
+ (Object) dataWithContentsOfURL(aURL, options:mask, error:errorPtr)
Creates and returns a data object containing the data from the location specified by aURL.
+ (Object) dataWithData(aData)
Creates and returns a data object containing the contents of another data object.
Instance Method Details
- (Object) bytes
Returns a pointer to the receiver’s contents. If the length of the receiver is 0, this method returns nil.
- (String) description
Returns an NSString object that contains a hexadecimal representation of the receiver’s contents.
- (Object) getBytes(buffer, length:length)
Copies a number of bytes from the start of the receiver's data into a given buffer. The number of bytes copied is the smaller of the length parameter and the length of the data encapsulated in the object.
- (Object) getBytes(buffer, range:range)
Copies a range of bytes from the receiver’s data into a given buffer. If range isn’t within the receiver’s range of bytes, an NSRangeException is raised.
- (Object) initWithBytes(bytes, length:length)
Returns a data object initialized by adding to it a given number of bytes of data copied from a given buffer. A data object initialized by adding to it length bytes of data copied from the buffer bytes. The returned object might be different than the original receiver.
- (Object) initWithBytesNoCopy(bytes, length:length)
Returns a data object initialized by adding to it a given number of bytes of data from a given buffer. The returned object takes ownership of the bytes pointer and frees it on deallocation. Therefore, bytes must point to a memory block allocated with malloc.
- (Object) initWithBytesNoCopy(bytes, length:length, freeWhenDone:flag)
Initializes a newly allocated data object by adding to it length bytes of data from the buffer bytes.
- (Object) initWithContentsOfFile(path)
Returns a data object initialized by reading into it the data from the file specified by a given path. This method is equivalent to initWithContentsOfFile:options:error: with no options.
- (Object) initWithContentsOfFile(path, options:mask, error:errorPtr)
Returns a data object initialized by reading into it the data from the file specified by a given path.
- (Object) initWithContentsOfURL(aURL)
Initializes a newly allocated data object initialized with the data from the location specified by aURL.
- (Object) initWithContentsOfURL(aURL, options:mask, error:errorPtr)
Returns a data object initialized with the data from the location specified by a given URL.
- (Object) initWithData(data)
Returns a data object initialized with the contents of another data object.
- (Boolean) isEqualToData(otherData)
Compares the receiving data object to otherData. Two data objects are equal if they hold the same number of bytes, and if the bytes at the same position in the objects are the same.
- (Integer) length
Returns the number of bytes contained in the receiver.
- (NSRange) rangeOfData(dataToFind, options:mask, range:searchRange)
Finds and returns the range of the first occurrence of the given data, within the given range, subject to given options.
- (NSData) subdataWithRange(range)
Returns a data object containing a copy of the receiver’s bytes that fall within the limits specified by a given range. If range isn’t within the receiver’s range of bytes, an NSRangeException is raised.A sample using this method can be found in “Working With Binary Data”.
- (Boolean) writeToFile(path, atomically:flag)
Writes the bytes in the receiver to the file specified by a given path.
- (Boolean) writeToFile(path, options:mask, error:errorPtr)
Writes the bytes in the receiver to the file specified by a given path.
- (Boolean) writeToURL(aURL, atomically:atomically)
Writes the bytes in the receiver to the location specified by aURL. Since at present only file:// URLs are supported, there is no difference between this method and writeToFile:atomically:, except for the type of the first argument.
- (Boolean) writeToURL(aURL, options:mask, error:errorPtr)
Writes the bytes in the receiver to the location specified by a given URL. Since at present only file:// URLs are supported, there is no difference between this method and writeToFile:options:error:, except for the type of the first argument.