How to return value from Alamofire

前端 未结 5 1960
忘掉有多难
忘掉有多难 2020-11-22 02:41

I am making url calls thru an API that I created using swift as follows:

class API {

  let apiEndPoint = \"endpoint\"
  let apiUrl:String!
  let consumerKey         


        
5条回答
  •  广开言路
    2020-11-22 03:10

    To parse a json using Swifty JSON, here is how i am doing it.

    For @Jenita _Alice4Real

    func uploadScans(parameters: [String: AnyObject], completionHandler: (AnyObject?, NSError?) -> ()) {
        makePostCall(CommonFunctions().getSaveSKUDataUrl(), parameters: parameters,completionHandler: completionHandler)
    }
    
    func makePostCall(url: String, parameters: [String: AnyObject], completionHandler: (AnyObject?, NSError?) -> ()) {
        Alamofire.request(.POST, url, parameters: parameters)
            .responseJSON { response in
                switch response.result {
                    case .Success(let value):
                        completionHandler(value, nil)
                    case .Failure(let error):
                        completionHandler(nil, error)
                }
        }
    }
    
    uploadScans(params) { responseObject, error in
        let json = JSON(responseObject!)
    }
    

提交回复
热议问题