无法使用类型为“(NSMutableURLRequest, (_, _, _) throws -> _)"的参数列表调用“dataTaskWithRequest" [英] Cannot invoke 'dataTaskWithRequest' with an argument list of type '(NSMutableURLRequest, (_, _, _) throws -> _)'

查看:35
本文介绍了无法使用类型为“(NSMutableURLRequest, (_, _, _) throws -> _)"的参数列表调用“dataTaskWithRequest"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 7 Beta 中开始使用 Swift 2 后,出现错误 cannot invoke.导致此问题的原因是什么?

After start using Swift 2 in Xcode 7 Beta, I get an error cannot invoke. What cause this issue?

我尝试通过以下 2 个问题找出我的问题,但我仍然收到错误消息:问题 1问题 2

I try to figure out my problem by following these 2 questions, but i still get the error: Question 1, Question 2

错误:

无法使用参数列表类型调用dataTaskWithRequest"'(NSMutableURLRequest, (_, _, _) 抛出 -> _)'

Cannot invoke 'dataTaskWithRequest' with an argument list of type '(NSMutableURLRequest, (_, _, _) throws -> _)'

完整代码

let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {data, response, error in
            let json = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? NSDictionary

            if let parseJSON = json {
                let resultValue:String = parseJSON["status"] as! String

                if(resultValue=="Success"){

                    //Store Confimed Account Detail Inside Core Data
                    try self.saveAccountDetail(userloginTextField!, confirmDataRetrieve: 0)

                    //Login is Successful
                    NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn")
                    NSUserDefaults.standardUserDefaults().synchronize()

                    self.dismissViewControllerAnimated(true, completion: nil)

                }
            }

        }

推荐答案

感谢 Leo Dabus,在他的帮助下,我发现这是 Swift 2 中的新功能.您输入代码的方式应该是 trytry! 处理

Thanks to Leo Dabus, with his help I figure out that this is the new feature in Swift 2. the way you type in the code should be to try or try! Handling

NSJSONSerialization 应该运行:(如果抛出输入你删除 !)

NSJSONSerialization should be run: (if is throwing input your remove the !)

let json = try!NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary

这篇关于无法使用类型为“(NSMutableURLRequest, (_, _, _) throws -> _)"的参数列表调用“dataTaskWithRequest"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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