Conditional for MessageComposeResult in MFMessageComposeViewController with swift [duplicate]

元气小坏坏 提交于 2019-12-11 00:12:54

问题


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.



来源:https://stackoverflow.com/questions/25020826/conditional-for-messagecomposeresult-in-mfmessagecomposeviewcontroller-with-swif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!