我正在尝试将代码从现有的应用转换为swift 3(Xcode 8.1),但我仍然停留在下面的代码中给出了错误:
cannot convert value of type (RKObjectRequestOperation!, RKMappingResult!) -> Void to expected argument type (RKObjectRequestOperation?, RKMappingResult?) -> Void!)
这是我的代码:
class func getShoppingItemsForPage(_ page: Int,pageSize: Int,
completionHandler:@escaping ([ShopItemModel]?,NSError?) -> ()) {
RKObjectManager.sharedManager().getObjectsAtPath("search",
parameters: ["page" : page, "pagesize" : pageSize], success: { (request: RKObjectRequestOperation!, result: RKMappingResult!) -> Void in
let resultArray = result.array() as? [ShopItemModel]
completionHandler(resultArray,nil)
}) { (request: RKObjectRequestOperation!, error: NSError!) -> Void in
completionHandler(nil,error)
}
}
我怀疑这可能与我所看到的FBSDKLoginManager中的类似错误有关
Cannot convert value of type (FBSDKLoginManagerLoginResult!, NSError!) -> Void to expected argument type "FBSDKLoginManagerRequestTokenHandler!"
以下是产生错误的Facebook代码。
loginManager.logIn(withReadPermissions: facebookReadPermissions, from: self, handler: {(result:FBSDKLoginManagerLoginResult!,error:NSError!) -> Void in
if error != nil {
// Process Error
}
else if result.isCancelled {
// Cancelled by User
}
else {
let delegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate
delegate.showMainStoryboard()
}
})
答案 0 :(得分:0)
set
答案 1 :(得分:0)
解决方案是将错误类型从NSError更改为Error并使调用和结果参数可选。