title: Swift 3.0 Writing binary image data with write(toFile: atomically:)
body: <p>I'm working through a tutorial <a href="https://www.hackingwithswift.com/read/10/4/importing-photos-with-uiimagepickercontroller" rel="nofollow">Project10</a> and trying to convert it to Swift 3.0 as I go. It is the usually straight forward case of using a <strong>UIImagePickerController</strong> to select an image and then save it to the <strong>Documents Directory</strong>.</p>
  
  <p>I'm getting an error on this line:</p>
  
  <pre><code>jpegData.write(toFile: imagePath, atomically: true)
  </code></pre>
  
  <p>Which began life as this:</p>
  
  <pre><code>jpegData.writeToFile(imagePath, atomically: true)
  </code></pre>
  
  <p>The error wants to replace my arguments with:</p>
  
  <pre><code>jpegData.write(to: imagePath, options: true)
  </code></pre>
  
  <p>I'm pretty sure that's not what I want and it leads to further String/URL errors anyway. The two methods, in full are:</p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
      var newImage: UIImage
  
      if let possibleImage = info[UIImagePickerControllerEditedImage] as? UIImage {
          newImage = possibleImage
      } else if let possibleImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
          newImage = possibleImage
      } else {
          return
      }
  
      let imageName = NSUUID().uuidString
      let imagePath = getDocumentsDirectory().appendingPathComponent(imageName)
  
      if let jpegData = UIImageJPEGRepresentation(newImage, 80) {
          jpegData.write(toFile: imagePath, atomically: true)
      }
  
      dismiss(animated: true, completion: nil)
  }
  
  func getDocumentsDirectory() -&gt; NSString {
      let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
      let documentsDirectory = paths[0]
      return documentsDirectory
  }
  </code></pre>
  
  <p>Am I simply getting confused with Strings, NSStrings and URLs?</p>