Initializer

init(contentsOfFile:encoding:)

Returns an NSString object initialized by reading data from the file at a given path using a given encoding.

Declaration

convenience init(contentsOfFile path: String, encoding enc: UInt) throws

Parameters

path

A path to a file.

enc

The encoding of the file at path. For possible values, see NSStringEncoding.

error

If an error occurs, upon return 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 the file named by path using the encoding, enc. The returned object may be different from the original receiver. If the file can’t be opened or there is an encoding error, returns nil.

Discussion

See Also

Creating and Initializing a String from a File

init(contentsOfFile: String, usedEncoding: UnsafeMutablePointer<UInt>?)

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