我試圖代碼從現有的應用程序轉換爲SWIFT 3(Xcode中8.1),但我被困在下面的代碼給錯誤:斯威夫特3 RKObjectRequestOperation返回錯誤無法類型RKObjectRequestOperation的轉換
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()
}
})
這可能有助於https://github.com/ekreative/testbuild-rocks-ios/blob/master/AppsV2/AVRequestHelper.swift – zombie