I have a simple app with text field (email) and a submit button. I have the emails stored in a txt file every time the form is used. Currently, every time a new email comes in, the previous gets deleted. I would like to add the "new email" to next line. I believe the right word is append to the next line. Here's my code:
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var emailField: NSTextField!
@IBAction func submitButton(sender: AnyObject) {
let myText = self.emailField.stringValue + ("\r\n")
let path = "/Users/my-user-name/Desktop/codes.txt"
let dir = (path as NSString).stringByDeletingLastPathComponent
do {
try myText.writeToFile(path, atomically: true, encoding: NSUTF8StringEncoding)
} catch let error as NSError {
print("error loading from path \(path)")
print(error.localizedDescription)
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
Any help would be really appreciate it. Thank you for your time.