0

Having trouble doing this in Swift..Super easy in Objective C. The error I get in the log is this:

2015-01-31 22:16:58.734 fun facts[15208:623304] Unknown class Settings in Interface Builder file.
2015-01-31 22:17:10.783 fun facts[15208:623304] -[UIViewController sendEmail:]: unrecognized selector sent to instance 0x7f9b7bc2fa30
2015-01-31 22:17:10.794 fun facts[15208:623304] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController sendEmail:]: unrecognized selector sent to instance 0x7f9b7bc2fa30'

See my code below. Any ideas what I do wrong?

//////////////////////SEND EMAIL


    @IBAction func sendEmail(sender: AnyObject) {

        var emailTitle = "Test Email"
        var messageBody = "This is a test email body"
        var toRecipents = ["yolo@mail.com"]
        var mc: MFMailComposeViewController = MFMailComposeViewController()
        mc.mailComposeDelegate = self
        mc.setSubject(emailTitle)
        mc.setMessageBody(messageBody, isHTML: false)
        mc.setToRecipients(toRecipents)

        self.presentViewController(mc, animated: true, completion: nil)
    }



    func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
        switch result.value {
        case MFMailComposeResultCancelled.value:
            println("Mail cancelled")
        case MFMailComposeResultSaved.value:
            println("Mail saved")
        case MFMailComposeResultSent.value:
            println("Mail sent")
        case MFMailComposeResultFailed.value:
            println("Mail sent failure: \(error.localizedDescription)")
        default:
            break
        }
        self.dismissViewControllerAnimated(false, completion: nil)
}

}
NobodyNada
  • 7,529
  • 6
  • 44
  • 51
user3615707
  • 89
  • 1
  • 9

1 Answers1

2

This sort of error can occur if you accidentally set a view's class to an incompatible custom class; for example, accidentally setting a UIButton's custom class to "Settings," i.e. a UIViewController class in this case, may have caused your particular error.

Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • Note that although this solution worked in this particular case, there are many other possible solutions that may solve similar errors: http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime , http://stackoverflow.com/questions/24924966/xcode-6-strange-bug-unknown-class-in-interface-builder-file – Lyndsey Scott Jan 31 '15 at 23:20