How to save data in document directory without replacing previous one

81 Views Asked by At

I am new in swift macos development, I am using this code but it is used to replace previous one but i want not to replace, I want to add new and also want to contain previous thanks in advance

let documentsUrl = FileManager.default.urls(for: .downloadsDirectory, in: .allDomainsMask)[0] as NSURL
    
 // add a filename
 let fileUrl = documentsUrl.appendingPathComponent("fl10_accounts.xml")
    
 // write to it
 //try! data
 try! data.write(to: fileUrl!, atomically: false, encoding: String.Encoding.utf8)
 print("File Created")

I am trying to add new data and also previously saved data in same named file

0

There are 0 best solutions below