objective c - MFMailComposeViewController in Swift -
objective c - MFMailComposeViewController in Swift -
this sample code:
import uikit import messageui class viewcontroller: uiviewcontroller, mfmailcomposeviewcontrollerdelegate { @ibaction func showemail(sender : anyobject) { var emailtitle = "test email" var messagebody = "this test email body" var torecipents = ["a.nakhimov@gmail.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) } override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func mailcomposecontroller(controller:mfmailcomposeviewcontroller, didfinishwithresult result:mfmailcomposeresult, error:nserror) { switch result { case mfmailcomposeresultcancelled: nslog("mail cancelled") case mfmailcomposeresultsaved: nslog("mail saved") case mfmailcomposeresultsent: nslog("mail sent") case mfmailcomposeresultfailed: nslog("mail sent failure: %@", [error.localizeddescription]) default: break } self.dismissviewcontrolleranimated(false, completion: nil) }
}
in function mailcomposecontroller error on every case expression:
could not find overload '~=' accepts supplied arguments.
what doing wrong?
i compared mfmailcomposeresult
documentation on both xcode 5 , xcode 6. in swift, mfmailcomposeresult
struct
struct mfmailcomposeresult { init(_ value: cunsignedint) // available in iphone 3.0 var value: cunsignedint }
with mfmailcomposeresultcancelled
constant of type mfmailcomposeresult
:
var mfmailcomposeresultcancelled: mfmailcomposeresult { }
while it's enum in objective-c:
enum mfmailcomposeresult { mfmailcomposeresultcancelled, mfmailcomposeresultsaved, mfmailcomposeresultsent, mfmailcomposeresultfailed }; typedef enum mfmailcomposeresult mfmailcomposeresult; // available in iphone 3.0
in order create code work, have compare values cunsignedint
.
so have type next code:
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) }
objective-c uiviewcontroller swift ios8 mfmailcomposer
Comments
Post a Comment