Check out example codes for "how to clear text file swift". It will help you in understanding the concepts better.

Code Example 1

let text = ""
do {
     try text.write(to: filePath, atomically: false, encoding: .utf8)
   } catch {
     print(error)
   }

Learn ReactJs, React Native from akashmittal.com