I've been searching stackoverflow and would like to know what the best practice is to unwrap the textfield.text optional without force unwrapping. It works doing this, but I've been told to never force unwrap. But when I assign textfield.text to something, I'm only just passing the optional string. Can someone explain what would be best for this? Thanks!
Edit:
func configuredMailComposeViewController() -> MFMailComposeViewController {
let passTextField = TextField.text
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject(passTextField!)
mailComposerVC.setMessageBody("Some Text", isHTML: false)
return mailComposerVC
}
I'm trying to pass a textfield text and pass it to the email subject. The force unwrap doesn't cause an error, but I would like to know what the best practice is to pass this string
Edit 2:
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
if let passTextField = textfield.text {
mailComposerVC.setSubject(passTextField)
}
mailComposerVC.setMessageBody("Some Text", isHTML: false)
return mailComposerVC
}