NSData(MBStringConversion) Category Reference

Declared in NSData+MBStringConversion.h

Overview

An NSData class extension that adds methods for converting between NSString and NSData instances.

Converting to and from hexadecimal representation

+ dataWithHexString:

Creates a new NSData instance by interpreting the passed-in string as a hexadecimal-encoded byte array.

+ (nullable NSData *)dataWithHexString:(nonnull NSString *)hexString

Parameters

hexString

The string to interpret as a hexadecimal representation of byte data.

Return Value

An NSData instance, or nil if hexString could not be intepreted as hexadecimal.

Declared In

NSData+MBStringConversion.h

– toStringHex

Returns a string containing a hexadecimal representation of the bytes contained in the receiver.

- (nonnull NSString *)toStringHex

Return Value

A hex string.

Declared In

NSData+MBStringConversion.h

Interpreting bytes as strings

– toStringUsingEncoding:

Interprets the receiver as a byte-encoded string using the given encoding.

- (nullable NSString *)toStringUsingEncoding:(NSStringEncoding)encoding

Parameters

encoding

The NSStringEncoding to use for interpreting the receiver.

Return Value

An NSString containing the receiver’s bytes interpreted as the specified encoding, or nil if the receiver could not be interpreted using that encoding.

Declared In

NSData+MBStringConversion.h

– toStringASCII

Interprets the receiver as a byte-encoded ASCII string.

- (nullable NSString *)toStringASCII

Return Value

An NSString containing the receiver’s bytes interpreted in ASCII format.

Declared In

NSData+MBStringConversion.h

– toStringUTF8

Interprets the receiver as a byte-encoded UTF-8 string.

- (nullable NSString *)toStringUTF8

Return Value

An NSString containing the receiver’s bytes interpreted in UTF-8 format.

Declared In

NSData+MBStringConversion.h

– toString

An alias for the toStringUTF8 method.

- (nullable NSString *)toString

Return Value

An NSString containing the receiver’s bytes interpreted in UTF-8 format.

Declared In

NSData+MBStringConversion.h