2016-11-29 56 views
0

我試圖代碼從現有的應用程序轉換爲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() 
      } 
     }) 
+0

這可能有助於https://github.com/ekreative/testbuild-rocks-ios/blob/master/AppsV2/AVRequestHelper.swift – zombie

回答

0
class func getShoppingItemsForPage(_ page: Int,pageSize: Int, 
             completionHandler:@escaping ([ShopItemModel]?,NSError?) ->()) { 

     RKObjectManager.sharedManager().getObjectsAtPath("search", 
                 parameters: ["page" : page, "pagesize" : pageSize], 
                 success: {(operation: RKObjectRequestOperation!, mappingResult: RKMappingResult!) -> Void in 
                 let resultArray = mappingResult.array() as? [ShopItemModel] 
                 completionHandler(resultArray,nil) 
     }, failure: {(operation: RKObjectRequestOperation!, error: NSError!) -> Void in 
     completionHandler(nil,error) 
     }) 
    } 
+0

這沒有奏效。有2個錯誤,如果我改變到上面,第4行仍然有相同的錯誤。如果我將第4行更改爲有問號,那麼您確定的代碼有錯誤。 – markhorrocks

+0

我的更新答案有效嗎? – zombie

+0

不,我在成功之後得到同樣的錯誤:' – markhorrocks

0

解決的辦法是從NSError更改錯誤類型錯誤,並撥打電話,並導致PARAMS可選。