title: How to write NSData to a new file in Swift?
body: <p>I am working to get the contents of an NSData instance written to a file. I am currently using an Xcode playground. </p>
  
  <p>This is my code:</p>
  
  <pre><code>let validDictionary = [
      "numericalValue": 1,
      "stringValue": "JSON",
      "arrayValue": [0, 1, 2, 3, 4, 5]
  ]
  
  let rawData: NSData!
  
  
  if NSJSONSerialization.isValidJSONObject(validDictionary) {
      do {
          rawData = try NSJSONSerialization.dataWithJSONObject(validDictionary, options: .PrettyPrinted)
          try rawData.writeToFile("newdata.json", options: .DataWritingAtomic)
      } catch {
          // Handle Error
      }
  }
  </code></pre>
  
  <p>I have a file named newdata.json located in resources but when I check it there is nothing inside. I also tried deleting and seeing if the file will be created but it still doesn't work. </p>