Conditional for MessageComposeResult in MFMessageC

2019-07-09 03:49发布

I am attempting to implement the MFMessageComposeViewControllerDelegate's required method

 func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {
    }

The issue is that I can't figure out how to compare the MessageComposeResult with its associated constants in swift(MessageComposeResultCancelled, MessageComposeResultSent, MessageComposeResultFailed). So far I have tried:

result == MessageComposeResultCancelled

and

result == MessageComposeResult(0)

both of which return the error "'MessageComposeResult' is not convertible to MirrorDisposition". Any insight on how I can resolve this error would be greatly appreciated.

标签: ios swift ios8
2条回答
倾城 Initia
2楼-- · 2019-07-09 04:07

Use .MessageComposeResultCancelled or the equivalents or, perhaps, result.value == MessageComposeResultCancelled

查看更多
你好瞎i
3楼-- · 2019-07-09 04:08

you are close but no cigar.

As a general rule of thumb, if the objC version is something like

MessageComposeResultCancelled

then the Swift equivalent is

MessageComposeResult.Cancelled

or in situations where the type MessageComposeResult is implied, you can just short hand it with

.Cancelled

EDIT

I was completely wrong about that result == MessageComposeResultCancelled worked for me. I know you tried this already, so just double check that you have imported the MessageUI.framework into your project and make sure you import MessageUI.

查看更多
登录 后发表回答