I have a function where I want to create a CSV file if it doesnt exist and add data to it. If it does exist I want to add this data as a new line each time its called.
Here is my current code, at the moment it just overwrites the entire file each time:
func writeTrackedSymptomValues(symptom: String, comment: String, time: String, timestamp: String) {
    symptomData = SymptomData()
    for _ in 0..<5 {
        symptomData.symptom = symptom
        symptomData.severity = self.severity
        symptomData.comment = comment
        symptomData.timestamp = timestamp
        symptom_data.append(symptomData!)
    }
    creatCSV()
}
func creatCSV() -> Void {
        let fileName = "symptom_data.csv"
        let path = self.getDocumentsDirectory().appendingPathComponent(fileName)
        var csvText = "Symptom,Severity,Comment,Time\n"
            let newLine = "\(symptomData.symptom),\(symptomData.severity),\(symptomData.comment),\(symptomData.timestamp)\n"
            csvText.append(newLine)
        do {
            try csvText.write(to: path, atomically: true, encoding: String.Encoding.utf8)
        } catch {
            print("Failed to create file")
            print("\(error)")
        }
        print(path ?? "not found")
}
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]
}
How can I add a new line each time instead?swift