Read string from file


I have a text file and want to read its contents into a String.


// Set the file path
let path = "myfile.txt"

do {
    // Get the contents
    let contents = try NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding)
catch let error as NSError {
    print("Ooops! Something went wrong: \(error)")

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)