Search code examples
swift3mfmailcomposeviewcontroller

How to pass text value to MFMailcomposeView Controller


Hi guys faily newbie here tons to learn in IOS

I am using messageUI and I want to pass a text value to MFmailComposeviewController

this is why I have try so far

  var userdata = String(txtUserEmail.Text)  

  let mail = MFMailComposeViewController()

  mail.setToRecipients([" \(userdata)"])

for somereason when I enter a email address it does not show in the composer of course there are other parts to the code that I have not included on here. As the main problem is i am unable to pass this value to the setToRecipients([])

any support would be most welcome here


Solution

  • Is txtUserEmail a UITextField?

    If so declare your userdata like this:

    let userdata = txtUserEmail.text
    mail.setToRecipients(userdata!)
    

    A UITextField.text (not "Text") already returns a string.