0

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.

Manolo
  • 469
  • 6
  • 20

1 Answers1

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.

Community
  • 1
  • 1
Shamas S
  • 7,507
  • 10
  • 46
  • 58