Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

messageComposeViewController Error in Swift 2

Tags:

ios

swift

swift2

The following code worked in Swift 1.2. Now, I get an error:

"Value of type MessageComposeResult has no member 'value'"

func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {
    switch (result.value) {
    case MessageComposeResultCancelled.value:
        print("Message was cancelled")
        self.dismissViewControllerAnimated(true, completion: nil)
    case MessageComposeResultFailed.value:
        print("Message failed")
        self.dismissViewControllerAnimated(true, completion: nil)
    case MessageComposeResultSent.value:
        print("Message was sent")
        self.dismissViewControllerAnimated(true, completion: nil)
    default:
        break;
    }
}

What member of the result am I supposed to check in order to find the status of the message in Swift 2?

like image 824
patrickd Avatar asked Sep 17 '15 07:09

patrickd


2 Answers

In Swift 2, value does not exist in result.

Use result.rawValue, instead.

like image 141
Unheilig Avatar answered Sep 19 '22 19:09

Unheilig


use rawValue instead of value

   switch result.rawValue {
    case MessageComposeResult.Cancelled.rawValue:
        print("Message was cancelled")
        controller.dismissViewControllerAnimated(true, completion: nil)

    case MessageComposeResult.Failed.rawValue:
        print("Message failed")
        controller.dismissViewControllerAnimated(true, completion: nil)

    case MessageComposeResult.Sent.rawValue:
        print("Message was sent")
        controller.dismissViewControllerAnimated(false, completion: nil)

    default:
        break
        controller.dismissViewControllerAnimated(true, completion: nil)
    }
like image 32
Muhammad Nawaz Avatar answered Sep 19 '22 19:09

Muhammad Nawaz