内容简介:http://stackoverflow.com/questions/39508868/completion-handlers-error-in-swift-3-and-xcode-8
我在Xcode 7.3中使用swift 2.2版本的工作项目.现在我已经更新了Xcode 8并迁移到swift 3.现在我的项目包含错误,特别是成功阻止网络的块.
哪个给出错误
Cannot convert value of type '() -> ()' to expected argument type '((URLSessionDataTask, Any?) -> Void)?'
我不明白如何解决这个工作,根据swift 3.
而且还有同样的错误在Facebook登录.
哪个给出错误
Cannot convert value of type '(FBSDKLoginManagerLoginResult!, NSError!) -> Void' to expected argument type 'FBSDKLoginManagerRequestTokenHandler!'
和
Cannot convert value of type '(_, _, NSError!) -> Void' to expected argument type 'FBSDKGraphRequestHandler!'
这个所有错误都与swift 3中的处理程序块相关.我不明白错误,因此无法解决.任何帮助将不胜感激.提前致谢.
虽然我以前不知道这个错误,Xcode想要通知我有关错误,但是我已经删除了类型规范与对象,它的工作.
如
manager.post(methodname, parameters: param, progress: nil, success:{ (dataTask, responseObj) in
if let dict : NSDictionary = responseObj as? NSDictionary {
print("Response of \(methodname) : \(dict)")
if dict.object(forKey: "response") as? String == "success" {
CompletionHandler(true, dict)
} else {
CompletionHandler(false, dict)
}
}
})
这里关于问题的错误在dataTask和responseObj中给出,它们是类型指定的.删除后,它工作正常.
和facebook登录一样
@IBAction func fbLoginClicked(_ sender: AnyObject) {
let app = UIApplication.shared.delegate as! AppDelegate
app.fbLoginManager = FBSDKLoginManager()
app.fbLoginManager.logOut()
app.fbLoginManager.loginBehavior = FBSDKLoginBehavior.native
app.fbLoginManager.logIn(withReadPermissions: ["email"], from: self, handler: { (result, error) -> Void in
if error != nil {
print(error?.localizedDescription)
} else {
if (result! as FBSDKLoginManagerLoginResult).isCancelled == true {
} else {
self.fetchFacebookUserDetail()
}
}
})
}
这里我也删除了结果的类型规格和错误,解决了问题.并在整个应用程序中遵循这一点,它的工作.我可以运行该项目没有错误,它也正在工作.谢谢.
http://stackoverflow.com/questions/39508868/completion-handlers-error-in-swift-3-and-xcode-8
以上所述就是小编给大家介绍的《ios – 完成处理程序在swift 3和Xcode 8中的错误》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- ios – Xcode 7.3无法完成操作(LaunchServicesError错误0)
- JqueryUI自动完成错误:未捕获TypeError:对象#的属性“结果”不是函数
- objective-c -gdb remote返回错误:E08调用完成块时(EXC_BAD_ACCESS)
- 利用python完成大学刷课(从0到完成的思路)
- 如何用短信完成XSS?
- 神经网络如何完成表征?
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
HTML Dog
Patrick Griffiths / New Riders Press / 2006-11-22 / USD 49.99
For readers who want to design Web pages that load quickly, are easy to update, accessible to all, work on all browsers and can be quickly adapted to different media, this comprehensive guide represen......一起来看看 《HTML Dog》 这本书的介绍吧!