无法将 '(String!, Bool, [AnyObject]!, NSError!)->Void 类型的值分配给 UIActivityViewControllerCompletionWithItemsHandler 类型的值? [英] Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type UIActivityViewControllerCompletionWithItemsHandler?'

查看:37
本文介绍了无法将 '(String!, Bool, [AnyObject]!, NSError!)->Void 类型的值分配给 UIActivityViewControllerCompletionWithItemsHandler 类型的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有以下几行代码...

I have the following lines of code in my project...

@IBAction func shareMeme(sender: UIBarButtonItem) {

    let newMeme = save()
    let memedImage = newMeme.memedImage
    let activityViewController = UIActivityViewController(activityItems: [memedImage], applicationActivities: nil)

    presentViewController(activityViewController, animated: true, completion: nil)

    activityViewController.completionWithItemsHandler = {(type: String!, completed: Bool, returnedItems: [AnyObject]!, error: NSError!) -> Void in

        dispatch_async(dispatch_get_main_queue()){
            self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
        }
    }
}

我不断收到编译器错误无法将类型为 '(String!, Bool, [AnyObject]!, NSError!) -> Void' 的值分配给类型为 'UIActivityViewControllerCompletionWithItemsHandler?' 的值",指的是以下行代码...

I keep getting a compiler error "Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!) -> Void' to a value of type 'UIActivityViewControllerCompletionWithItemsHandler?'" referring to the following line of code...

    activityViewController.completionWithItemsHandler = {(type: String!, completed: Bool, returnedItems: [AnyObject]!, error: NSError!) -> Void in

任何建议将不胜感激.

推荐答案

您的类型签名与 UIActivityViewControllerCompletionWithItemsHandler 的定义不匹配,即 (String?, Bool, [AnyObject]?,NSError?)->无效.用 ?s 替换你的 !s,它应该可以正常工作.

Your type signature doesn't match the definition of UIActivityViewControllerCompletionWithItemsHandler, which is (String?, Bool, [AnyObject]?, NSError?) -> Void. Replace your !s with ?s and it should work fine.

这篇关于无法将 '(String!, Bool, [AnyObject]!, NSError!)->Void 类型的值分配给 UIActivityViewControllerCompletionWithItemsHandler 类型的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆