application tried to present a nil modal view controller on target

Swift
if MFMailComposeViewController.canSendMail() {
// Send mail code
}

Source

Also in Swift: