Advertisement
Don_Mag

Untitled

Jul 23rd, 2021
1,796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.67 KB | None | 0 0
  1. class ViewController: UIViewController {
  2.  
  3.     override func viewDidLoad() {
  4.         super.viewDidLoad()
  5.         // Do any additional setup after loading the view.
  6.        
  7.         let str = "Test Message"
  8.         let url = self.getDocumentsDirectory().appendingPathComponent("message.txt")
  9.        
  10.         do {
  11.             try str.write(to: url, atomically: true, encoding: .utf8)
  12.         } catch {
  13.             print(error.localizedDescription)
  14.         }
  15.  
  16.     }
  17.  
  18.     func getDocumentsDirectory() -> URL {
  19.         // find all possible documents directories for this user
  20.         let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
  21.        
  22.         // just send back the first one, which ought to be the only one
  23.         return paths[0]
  24.     }
  25.    
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement