Compose Email issues in Swift version 2.0

For some reason, I can't seem to get my compose email to work under swift 2.0. I did worked fine under swift version 1, but no longer work on version 2. Any suggestion? Thanks.

import UIKit
import MessageUI

    class EmailViewController: UITableViewController, MFMailComposeViewControllerDelegate, UITextFieldDelegate  {

       let userDefaults = NSUserDefaults.standardUserDefaults()

        @IBOutlet weak var name: UITextField!
        @IBOutlet weak var phone: UITextField!
        @IBOutlet weak var email: UITextField!

        @IBAction func SendEmailButton(sender: AnyObject) {

            let fields: [UITextField] = [name, phone, email]

            let messageBody = "Name:\(name.text)\nPhone:\(phone.text)\nEmail:\(email.text)"

            let emailTitle = "Interface Information"
            let toRecipents = [""]
            let mc: MFMailComposeViewController = MFMailComposeViewController()
            mc.mailComposeDelegate = self
            mc.setSubject(emailTitle)
            mc.setMessageBody(messageBody, isHTML: false)
            mc.setToRecipients(toRecipents)
            self.presentViewController(mc, animated: true, completion: nil)

        }
        override func viewDidAppear(animated: Bool) {

            name.text = userDefaults.stringForKey("name")  
            phone.text = userDefaults.stringForKey("phone")
            email.text = userDefaults.stringForKey("email")
        }
    }

Answers


You seem to have some issues with your textfields. I would probably guess that the outlets does not work and you could test to drag them again. I created a sample project for you that you can check how I have done it with your code and see if it helps you. You can download the code from here.


Need Your Help

Can you receive SMS messages in your app on iPhones?

iphone sms

I am wondering if you can officially receive SMS messages in your app (and remove the default SMS app). I believe it can be done on Android, I just wonder if this is possible on iPhone OS.