title: How to create a file in an iOS App made with Swift?
body: <p>I need to save some data in my iOS App. To do so I want to create a basic text file that I can then call again from elsewhere in my App. But my create File request always returns false.</p>
  
  <pre><code>let fileMang = FileManager.default
  let home = NSHomeDirectory()
  let filePath = String(home) + "/AppData/Documents/points.txt"
  if fileMang.fileExists(atPath: filePath) {
      do {
          try fileMang.removeItem(atPath: filePath)
      }
      catch {}
  }
  let test = fileMang.createFile(atPath: filePath, contents: "0, 0, 0".data(using: String.Encoding.utf8), attributes: nil)
  print(test)
  </code></pre>
  
  <p>The "0, 0, 0" String is only supposed to be a placeholder. My actual data is written to the file later on. I tried to create an empty file at first with Data.init() but this did not work either so I switched to this placeholder. Ideally though the new file would be empty.</p>