无法分配类型'(String?,Bool,[AnyObject] ?, NSError?) - >的值()'至

时间:2016-09-15 01:19:22

标签: ios swift swift3

在我更新Xcode版本8.0(8A218a)swift 3之后,我收到了此错误

  

无法指定类型的值'(String?,Bool,[AnyObject] ?, NSError?) - > ()'输入' UIActivityViewControllerCompletionWithItemsHandler?'

activityview.completionWithItemsHandler = {(activityType: String?, completed:Bool, returnedItems:[AnyObject]?, error: NSError?) in
            if !completed {
                print("cancelled")
                return
            }else{
                complele()
            }

        }

我一直关注此Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type UIActivityViewControllerCompletionWithItemsHandler?'

但我仍然收到错误消息。

在以前的版本7.3.1 swift 2中运行良好。

1 个答案:

答案 0 :(得分:6)

使用UIActivityType代替String, [Any]代替[AnyObject]Error代替NSError

activityview.completionWithItemsHandler = {(activityType: UIActivityType?, completed:Bool, returnedItems:[Any]?, error: Error?) in
    if !completed {
        print("cancelled")
        return
    }else{
        complele()
    }
}

查看apple documentation了解更多详情。