Deprecated NSData Methods

A method identified as deprecated has been superseded and may become unsupported in the future.

Deprecated in OS X v10.6

getBytes:

Copies a data object’s contents into a given buffer. (Deprecated in OS X v10.6. This method is unsafe because it could potentially cause buffer overruns. You should use getBytes:length: or getBytes:range: instead.)

- (void)getBytes:(void *)buffer
Parameters
buffer

A buffer into which to copy the receiver's data. The buffer must be at least length bytes.

Discussion

You can see a sample using this method in “Working With Binary Data”.

Availability
  • Available in OS X v10.0 and later.
  • Deprecated in OS X v10.6.
Declared In
NSData.h

Deprecated in OS X v10.7

dataWithContentsOfMappedFile:

Creates and returns a data object from the mapped file specified by path. (Deprecated in OS X v10.7.)

+ (id)dataWithContentsOfMappedFile:(NSString *)path
Parameters
path

The absolute path of the file from which to read data.

Return Value

A data object from the mapped file specified by path. Returns nil if the data object could not be created.

Discussion

Because of file mapping restrictions, this method should only be used if the file is guaranteed to exist for the duration of the data object’s existence. It is generally safer to use the dataWithContentsOfFile: method.

This methods assumes mapped files are available from the underlying operating system. A mapped file uses virtual memory techniques to avoid copying pages of the file into memory until they are actually needed.

Availability
  • Available in OS X v10.0 and later.
  • Deprecated in OS X v10.7.
Related Sample Code
Declared In
NSData.h

initWithContentsOfMappedFile:

Returns a data object initialized by reading into it the mapped file specified by a given path. (Deprecated in OS X v10.7.)

- (id)initWithContentsOfMappedFile:(NSString *)path
Parameters
path

The absolute path of the file from which to read data.

Return Value

A data object initialized by reading into it the mapped file specified by path. The returned object might be different than the original receiver.

Availability
  • Available in OS X v10.0 and later.
  • Deprecated in OS X v10.7.
Declared In
NSData.h

Deprecated in OS X v10.9

base64Encoding

Create a Base-64 encoded NSString from the receiver's contents. (Deprecated in OS X v10.9. You should transition to either base64EncodedStringWithOptions: or base64EncodedDataWithOptions:)

- (NSString *)base64Encoding
Return Value

A Base-64 encoded string.

Special Considerations

Although this method was only introduced publicly for iOS 7, it has existed since iOS 4; you can use it if your application needs to target an operating system prior to iOS 7. This method behaves like base64EncodedStringWithOptions:, but ignores all unknown characters.

Availability
  • Available in OS X v10.6 and later.
  • Deprecated in OS X v10.9.
Declared In
NSData.h

initWithBase64Encoding:

Returns a data object initialized with the given Base-64 encoded string. (Deprecated in OS X v10.9. You should transition to either initWithBase64EncodedString:options: or initWithBase64EncodedData:options:.)

- (id)initWithBase64Encoding:(NSString *)base64String
Parameters
base64String

A Base-64 encoded string.

Return Value

A data object built by Base-64 decoding the provided string. Returns nil if the data object could not be decoded.

Special Considerations

Although this method was only introduced publicly for iOS 7, it has existed since iOS 4; you can use it if your application needs to target an operating system prior to iOS 7. This method behaves like initWithBase64EncodedString:options:, but ignores all unknown characters.

Availability
  • Available in OS X v10.6 and later.
  • Deprecated in OS X v10.9.
Declared In
NSData.h