2015-09-17 14 views
5

Mã sau hoạt động trong Swift 1.2. Bây giờ, tôi nhận được một lỗi:messageComposeViewController Lỗi trong Swift 2

"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; 
    } 
} 

gì thành viên của kết quả tôi phải kiểm tra để tìm ra tình trạng của tin nhắn trong Swift 2?

Trả lời

12

Trong Swift 2, value không tồn tại trong result. Ví dụ:

Sử dụng result.rawValue.

+1

Cảm ơn bạn! @Unheilig – patrickd

0

sử dụng rawValue thay vì giá trị

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) 
    } 
+1

Bạn có thể thêm giải thích về những gì đã thay đổi không? – rjdkolb

+0

Cảm ơn câu trả lời của bạn. Để cải thiện nó, bạn có thể thêm giải thích về những gì bạn đã thay đổi và tại sao những thay đổi đó giải quyết vấn đề của OP. – Tom

Các vấn đề liên quan