title: Simple Swift file download with URL
body: <p>So I have the URL as string (in this case a JPG but would like a general procedure for any file type if possible) and I have the file path as string where I want to save the file.</p>
  
  <p>What would be the fastest way to get this implemented? </p>
  
  <p>Please keep in mind this is for OSX command line application. I tried few sample codes found here, mostly using UIImage but I get error:"Use of unresolved identifier", adding "import UIKit" gets me error:"No such  Module". Please help!</p>
  
  <pre><code>import Foundation
  
  let myURLstring = "http://www.safety.vanderbilt.edu/images/staff/Bob-Wheaton.jpg"
  let myFilePathString = "/Volumes/HD/Staff Pictures/Bob-VEHS.jpg"
  </code></pre>
  
  <p>---> ABOVE IS THE ORIGINAL QUESTION &lt;---</p>
  
  <p>---> BELOW IS NEW IMPROVED CODE: WORKING &lt;---</p>
  
  <pre><code>import Foundation
  
  let myURLstring = "http://www.safety.vanderbilt.edu/images/staff/Bob-Wheaton.jpg"
  let myFilePathString = "/Volumes/HD/Staff Pictures/Bob-VEHS.jpg"
  
  let url = NSURL(string: myURLstring)
  let imageDataFromURL = NSData(contentsOfURL: url)
  
  let fileManager = NSFileManager.defaultManager()
  fileManager.createFileAtPath(myFilePathString, contents: imageDataFromURL, attributes: nil)
  </code></pre>