Type Method

stringWithContentsOfURL:usedEncoding:error:

Returns a string created by reading data from a given URL and returns by reference the encoding used to interpret the data.

Declaration

+ (instancetype)stringWithContentsOfURL:(NSURL *)url usedEncoding:(NSStringEncoding *)enc error:(NSError * _Nullable *)error;

Parameters

url

The URL from which to read data.

enc

Upon return, if url is read successfully, contains the encoding used to interpret the data. For possible values, see NSStringEncoding.

error

If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.

Return Value

A string created by reading data from url. If the URL can’t be opened or there is an encoding error, returns nil.

Discussion

This method attempts to determine the encoding at url.

See Also

Creating and Initializing a String from an URL

+ stringWithContentsOfURL:encoding:error:

Returns a string created by reading data from a given URL interpreted using a given encoding.

- initWithContentsOfURL:encoding:error:

Returns an NSString object initialized by reading data from a given URL interpreted using a given encoding.

- initWithContentsOfURL:usedEncoding:error:

Returns an NSString object initialized by reading data from a given URL and returns by reference the encoding used to interpret the data.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software