I have been pulling my hair out lately trying to create a .txt file into an email.
I have a variable which is a list of strings that I want to write to a txt file, and then add as an attachment to an email.
I have not been able to find any decent documentation on this.
Looking forward to some great input. Thank you!
Edit---------- I found this code sample: and I am getting the following error.
@IBAction func createFile(sender: AnyObject) {
let path = tmpDir.stringByAppendingPathComponent(fileName)
let contentsOfFile = "Sample Text"
var error: NSError?
// Write File
if contentsOfFile.writeToFile(path, atomically: true, encoding: NSUTF8StringEncoding, error: &error) == false {
if let errorMessage = error {
println("Failed to create file")
println("\(errorMessage)")
}
} else {
println("File sample.txt created at tmp directory")
}
}
let path = tmpDir.stringByAppendingPathComponent(fileName)
I am getting an error telling me "Value of type 'String' has no member URLByAppendingPathComponent' "
How do I fix that?