I have a simple calculator which display the results in a label, I want to export the results to a pdf, email, or text file. Any clue how could I make it? Thanks in advance.
Asked
Active
Viewed 41 times
1 Answers
1
Just get the value of your UILabel.text. After that saving it to a file should be pretty easy.
let file = "file.txt"
if let dirs : [String] = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String] {
let dir = dirs[0] //documents directory
let path = dir.stringByAppendingPathComponent(file);
let text = myLabel.text
//writing
text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil);
Copied the code from this answer here.
-
Just what I need :) Thank you iosDev82 :) – Manolo Apr 08 '15 at 06:09
-
@Manolo Glad to be of help. Have a great day. :) – Shamas S Apr 08 '15 at 06:10