Swift email from a custom framework fails
<p>I have made a custom framework (Swift) which i use in several different apps.</p>

<p>One functionality i have put in this framework is a basic email client.</p>

<p>The code is below but it currently portrays the following behaviour: </p>

<p>Initially loads the email page view perfectly, all the fields are presented how i would expect (i.e. Address, BCC, Subject, Attachments etc) however when i press send or cancel, the app crashes. It actually sends the email though. I have put a print in the "public func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?)" and its never printed.</p>

<p>Please see code below:</p>

<p>Framework</p>

<pre><code>import UIKit
import MessageUI


public class Framework_Email : NSObject, MFMailComposeViewControllerDelegate{

    var picker : MFMailComposeViewController!

    public var EmailSubject    : String = ""
    public var EmailMessage    : String = ""
    public var EmailAddress    : [String] = []
    public var EmailBlindAddress    : [String] = []
    public var EmailAttachment : [NSDictionary] = []

    public func SendEmail(View : UIViewController)
    {
        picker = MFMailComposeViewController()
        picker.mailComposeDelegate = self
        picker.setToRecipients(EmailAddress)
        picker.setSubject(EmailSubject)
        picker.setMessageBody(EmailMessage, isHTML: false)
        picker.setBccRecipients(EmailBlindAddress)

        for temp in EmailAttachment
        {
            picker.addAttachmentData(temp["Data"] as! NSData, mimeType: temp["Type"] as! String, fileName: temp["Name"]as! String)
        }
        View.presentViewController(picker, animated: true, completion: nil)
    }

    public func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result:     MFMailComposeResult, error: NSError?) {
        print("Im Here!!!!!") //This is never seen in the output
        picker.dismissViewControllerAnimated(true, completion: nil)
    }
}
</code></pre>

<p>And i call it by the following in my main app view controller</p>

<pre><code>let EmailClient : Framework_Email = Framework_Email()
EmailClient.EmailAddress = ["email@eailaddress.co.uk"]
EmailClient.EmailMessage = "Email Message"
EmailClient.EmailSubject = "Email Subject"
EmailClient.EmailBlindAddress = ["email@eailaddress.co.uk"]
EmailClient.SendEmail(self)
</code></pre>

<p>Can anyone suggest why this won't work?</p>

<p>Thanks</p>