Conditional for MessageComposeResult in MFMessageC

2019-07-09 03:23发布

问题:

This question already has an answer here:

  • xcode 6 beta 4 - MessageComposeResult is not convertible to OptionalNilComparisonType 4 answers

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.

回答1:

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



回答2:

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.



标签: ios swift ios8