简体   繁体   English

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

[英]Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type 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)
        }
    }
}

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... 我不断收到编译器错误“无法将类型的值'(String!,Bool,[AnyObject] !, NSError!) - > Void'赋值为'UIActivityViewControllerCompletionWithItemsHandler?'”,参考以下代码行。 ..

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

Any suggestions would be appreciated. 任何建议,将不胜感激。

Your type signature doesn't match the definition of UIActivityViewControllerCompletionWithItemsHandler , which is (String?, Bool, [AnyObject]?, NSError?) -> Void . 你的类型签名与UIActivityViewControllerCompletionWithItemsHandler的定义不匹配,它是(String?, Bool, [AnyObject]?, NSError?) -> Void Replace your ! 替换你的! s with ? ? s and it should work fine. s它应该工作正常。

With Swift 3.0 the signature should be 使用Swift 3.0,签名应该是

activityViewController.completionWithItemsHandler = { (activity: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in

As shown in this post 这篇文章所示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型'(String ?, Bool,[AnyObject] ?, NSError?)->()'的值分配给 - Cannot assign value of type '(String?, Bool, [AnyObject]?, NSError?) -> ()' to 无法分配类型 '[String : AnyObject] 的值 - Cannot assign value of type '[String : AnyObject] 无法将类型AnyObject的值分配给字符串类型的值 - Cannot assign a value of type AnyObject to a value of type String 无法将类型((Bool,NSError!)-> Void)的值转换为预期的参数类型'ACAccountStoreRequestAccessCompletionHandler!' - Cannot convert value of type '(Bool, NSError!) -> Void' to expected argument type 'ACAccountStoreRequestAccessCompletionHandler!' 无法将String类型的值分配为AnyObject类型? 斯威夫特3.0 - Cannot assign value of type String to type AnyObject? Swift 3.0 使用 SwiftyJSON,数组不能将 AnyObject 类型的值分配给 String 类型 - Using SwiftyJSON, array cannot assign value of type AnyObject to type String 无法调用非函数类型的值'((成功:Bool,错误:NSError?)throws - > Void)?) - Cannot call value of non-function type '((success: Bool, error: NSError?) throws -> Void)?) 无法使用类型为(([[AnyObject] !, NSError!)-> Void)'的参数列表调用'findObjectsInBackgroundWithBlock' - Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject]!, NSError!) -> Void)' 无法将类型为(()-> Void)的值分配为类型为((()-> Void)!'' - Cannot assign value of type '() -> Void' to type '(() -> Void)!' 无法将 Bool 类型的值分配给类型字符串数据库表示 - Cannot assign value of Bool type to type String Database Representation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM