Instance Method
initWithData:encoding:
Returns an NSString
object initialized by converting given data into UTF-16 code units using a given encoding.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Parameters
data
An NSData
object containing bytes in encoding
and the default plain text format (that is, pure content with no attributes or other markups) for that encoding.
encoding
Return Value
An NSString
object initialized by converting the bytes in data
into UTF-16 code units using encoding
. The returned object may be different from the original receiver. Returns nil
if the initialization fails for some reason (for example if data
does not represent valid data for encoding
).
See Also
Creating and Initializing Strings
- init
Returns an initialized NSString
object that contains no characters.
- initWithBytes:length:encoding:
Returns an initialized NSString
object containing a given number of bytes from a given buffer of bytes interpreted in a given encoding.
- initWithCharacters:length:
Returns an initialized NSString
object that contains a given number of characters from a given C array of UTF-16 code units.
- initWithString:
Returns an NSString
object initialized by copying the characters from another given string.
- initWithCString:encoding:
Returns an NSString
object initialized using the characters in a given C array, interpreted according to a given encoding.
- initWithUTF8String:
Returns an NSString
object initialized by copying the characters from a given C array of UTF8-encoded bytes.
- initWithFormat:
Returns an NSString
object initialized by using a given format string as a template into which the remaining argument values are substituted.
- initWithFormat:arguments:
Returns an NSString
object initialized by using a given format string as a template into which the remaining argument values are substituted without any localization.
- initWithFormat:locale:
Returns an NSString
object initialized by using a given format string as a template into which the remaining argument values are substituted according to given locale.
- initWithFormat:locale:arguments:
Returns an NSString
object initialized by using a given format string as a template into which the remaining argument values are substituted according to given locale information. This method is meant to be called from within a variadic function, where the argument list will be available.
+ stringWithFormat:
Returns a string created by using a given format string as a template into which the remaining argument values are substituted.
+ localizedStringWithFormat:
Returns a string created by using a given format string as a template into which the remaining argument values are substituted according to the current locale.
+ stringWithString:
Returns a string created by copying the characters from another given string.