2017-09-24 73 views
-1

額外的參數「方法」被抓我的頭,也能收到額外的參數「方法」在通話,全部是我把數據是正確的Kepp讓呼叫

ratingStar是雙數據類型

// Global Variable 
reviewDriverEndPoint = "www.mywebsite.com/api/review" 

func reviewDriver() { 

     let parameters: [String: AnyObject] = [ 
      "star": ratingStar as AnyObject, 
      "comment": reviewBox.text as AnyObject, 
      ] 
     Alamofire.request(reviewDriverEndPoint, method: .post, parameters: parameters, encoding: JSONEncoding.default) 
      .responseJSON { response in 
       if let value = response.result.value { 
        print(value) 
       } 
     } 

} 
+0

這有什麼問題呢? –

+0

我無法重現您的錯誤。 –

回答

0

Alamofire的方法不知道你是否將變量或函數作爲參數傳遞,因此它使用最近的本地名稱(在你的情況下是函數)。

你必須改變的函數或變量名稱,如

reviewDriverEndpoint = "www.mywebsite.com/api/review" 

func reviewDriver() { 

     let parameters: [String: AnyObject] = [ 
      "star": ratingStar as AnyObject, 
      "comment": reviewBox.text as AnyObject 
      ] 
     Alamofire.request(reviewDriverEndpoint, method: .post, parameters: parameters, encoding: JSONEncoding.default) 
      .responseJSON { response in 
       if let value = response.result.value { 
        print(value) 
       } 
     } 

}