Instance Method

initWithContentsOfURL:encoding:error:

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

Declaration

- (instancetype)initWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError * _Nullable *)error;

Parameters

url

The URL to read.

enc

The encoding of the file at path. 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, pass in NULL.

Return Value

An NSString object initialized by reading data from url. The returned object may be different from the original receiver. If the URL can’t be opened or there is an encoding error, returns nil.

Discussion

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.

+ 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.

- 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.