Skip to content

Instantly share code, notes, and snippets.

@duraiganesh0
Created December 1, 2016 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duraiganesh0/d4c1612e73c08548f234ab4ca132e48f to your computer and use it in GitHub Desktop.
Save duraiganesh0/d4c1612e73c08548f234ab4ca132e48f to your computer and use it in GitHub Desktop.
let employee : [String: AnyObject] = ["first_name": firstNameTextField.text! as AnyObject, "last_name": lastNameTextField.text! as AnyObject, "middle_name": middleNameTextField.text! as AnyObject, "email_id": emailTextField.text! as AnyObject, "encrypted_password": passwordTextField.text! as AnyObject]
let organization : [String: AnyObject] = ["org_name": orgNameTextField.text! as AnyObject, "location_id": (selectedCountry?.value)! as AnyObject, "address": orgAddressTextField.text! as AnyObject, "city": cityTextField.text! as AnyObject, "state": stateTextField.text! as AnyObject, "country": countryTextField.text! as AnyObject, "email": orgEmailTextField.text! as AnyObject]
let params : [String: [String: AnyObject]] = ["employee": employee as [String: AnyObject], "organisation": organization as [String: AnyObject]]
// this is the alamofire api call
Alamofire.request(signUpUrl, method: .post, parameters: params, encoding: URLEncoding.default, headers: nil).responseJSON { (responseData) -> Void in
print(responseData.response)
print(responseData.result.value)
switch responseData.result {
case .failure(let error):
print(error.localizedDescription)
case .success( _):
if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)
print(swiftyJsonVar)
//self.showAndHideViews(view: 4)
}
}
}
// this is the urlDataTask api call
var jsonDict = [String: AnyObject]()
Utils.makeHTTPPostRequest(path: signUpUrl, body: params as [String : AnyObject], onCompletion: { JSON, error -> Void in
guard error == nil else {
DispatchQueue.main.async(execute: {
print("error")
})
return
}
print(JSON)
if let dictJson = JSON.dictionaryObject {
jsonDict = dictJson as [String : AnyObject]
}
if let err = jsonDict["error"] {
DispatchQueue.main.async(execute: {
print("error")
})
return
} else {
print("success")
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment