Swift 3 RKObjectRequestOperation返回无法转换类型RKObjectRequestOperation的错误

时间:2016-11-29 19:44:26

标签: swift xcode restkit

我正在尝试将代码从现有的应用转换为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()
            }
        })

2 个答案:

答案 0 :(得分:0)

set

答案 1 :(得分:0)

解决方案是将错误类型从NSError更改为Error并使调用和结果参数可选。