title: Use of init(contentsOfFile:encoding:) Swift 4
body: <p>I want to get a string from a file. I've researched how to do it, and I've found the next code:</p>
  
  <pre><code>import Foundation
  
  // Read data from this file.
  let path = "/Users/samallen/file.txt"
  
  do {
      // Use contentsOfFile overload.
      // ... Specify ASCII encoding.
      // ... Ignore errors.
      var data = try NSString(contentsOfFile: path,
          encoding: String.Encoding.ascii.rawValue)
  
      // If a value was returned, print it.
      print(data)
  }
  </code></pre>
  
  <p>The important part are the lines:</p>
  
  <pre><code>var data = try NSString(contentsOfFile: path,
              encoding: String.Encoding.ascii.rawValue)
  </code></pre>
  
  <p>I looked in Apple's documentation about this and found init(contentsOfFile:usedEncoding:)</p>
  
  <p>What I don't get is why you can use String(contentsOfFile:usedEncoding:) instead of init(contentsOfFile:usedEncoding:). Why can you replace String for init? I have seen somthing similar with UIImage.</p>
  
  <p>Thanks in advance</p>