stevengbu
stevengbu

Reputation: 243

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.

Upvotes: 1

Views: 2679

Answers (1)

Nirav D
Nirav D

Reputation: 72450

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.

Upvotes: 6

Related Questions