stevengbu stevengbu - 2 months ago 158
iOS Question

Cannot assign value of type '(String?, Bool, [AnyObject]?, NSError?) -> ()' to

After I update Xcode Version 8.0 (8A218a) swift 3, I got this error


Cannot assign value of type '(String?, Bool, [AnyObject]?, NSError?) -> ()' to type 'UIActivityViewControllerCompletionWithItemsHandler?'


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

}


I have been following this Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type UIActivityViewControllerCompletionWithItemsHandler?'

But i still got the error message.

It works well in previous version 7.3.1 swift 2.

Answer

Use UIActivityType instead of String, [Any] instead of [AnyObject] and Error instead of NSError like this.

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

Check apple documentation for more detail.

Comments