xcode 6 beta 4 - MessageComposeResult is not convertible to OptionalNilComparisonType

后端 未结 4 508
陌清茗
陌清茗 2021-01-12 03:04

I have just upgraded from Xcode 6 Beta 3 to Beta 4. In 3 my app was compiling perfectly however in 4 I have the following error. Can anyone explain and provide a solution pl

相关标签:
4条回答
  • 2021-01-12 03:53

    For Swift 2, you will need to use rawValue:

    // MARK: MFMessageComposeViewControllerDelegate
    
    func messageComposeViewController(controller:MFMessageComposeViewController, didFinishWithResult result:MessageComposeResult) {
      controller.dismissViewControllerAnimated(true, completion:nil)
    
      switch result.rawValue {
    
      case MessageComposeResultSent.rawValue:
        print("cancelado")
    
      case MessageComposeResultCancelled.rawValue :
        print("canceled...")
    
      case MessageComposeResultFailed.rawValue :
        print("fail...")
    
      default:
        print("default...")
    
      }
    }
    

    Of course, if you're just interested in one particular value, you could use an if statement as such:

    if (result.rawValue ==  MessageComposeResultCancelled.rawValue) {
      // Message canceled.
    }
    
    0 讨论(0)
  • 2021-01-12 03:56
    func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
    
        switch result.value {
    
        case MessageComposeResultSent.value :
            println("enviado")
    
        case MessageComposeResultCancelled.value :
            println("cancelado")
    
        case MessageComposeResultFailed.value :
            println("fallo")
    
        default:
            println("")
    
        }
    
    }
    
    0 讨论(0)
  • 2021-01-12 04:06

    For Swift 3.0, you will need this:

    func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult){
    
        switch result.rawValue {
    
        case MessageComposeResult.sent.rawValue:
            print("sent")
            break
    
        case MessageComposeResult.cancelled.rawValue:
            print("cancelled")
            break
    
        case MessageComposeResult.failed.rawValue:
            print("failed")
            break
    
        default:
            break
        }
    
        self.dismiss(animated: true) { () -> Void in
    
        }
    }
    
    @IBAction func sentSMSAction(_ sender: AnyObject) {
    
        if MFMessageComposeViewController.canSendText() {
            let messageVC = MFMessageComposeViewController()
    
            messageVC.body = "My first custom SMS";
            messageVC.recipients = ["0123456789"]
            messageVC.messageComposeDelegate = self;
    
            self.present(messageVC, animated: false, completion: nil)
        }
    
    }
    
    0 讨论(0)
  • 2021-01-12 04:08

    It's a bug in the way this module is bridged to Swift. Report it. To use the module, stay in Objective-C until the Swift bridging bug is fixed.

    The main part of the bug as it stands seems to me to be:

    • This should be an enum, and it isn't; it's a struct

    • The struct has a value, which ought to be capable of comparison, but it has no getter (you can set it on initialization but you can't get it later)

    0 讨论(0)
提交回复
热议问题