Don_Mag icon

Untitled

Don_Mag | PRO | 07/23/21 07:09:31 PM UTC | 0 ⭐ | 2354 👁️ | Never ⏰ | []
Swift |

670 B

|

None

|

0 👍

/

0 👎

class ViewController: UIViewController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let str = "Test Message"
        let url = self.getDocumentsDirectory().appendingPathComponent("message.txt")
        
        do {
            try str.write(to: url, atomically: true, encoding: .utf8)
        } catch {
            print(error.localizedDescription)
        }
 
    }
 
    func getDocumentsDirectory() -> URL {
        // find all possible documents directories for this user
        let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
        
        // just send back the first one, which ought to be the only one
        return paths[0]
    }
    
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎