I tried some code but still, my issue is not resolved. Please help me i am new in swift code.
let parameters: Parameters = ["skey": "XXXXXX","country_code":"91","mobile":"XXX004","user_role":"4"]
AF.request("http://XXXXX/dev/clinic/api/v1/login_otp?", method: .get, parameters: parameters)
.responseJSON { (response) in
switch response.result {
case .success:
if let JSON = response.result.value as? [String: Any] {
let status = JSON["status"] as! String
print(status)
}
case .failure(let error): break
// error handling
}
}
bellow is the server responce
success({
message = "Otp sent successfully on +9170XXXX1004";
status = 1;
})
Follow the steps given in the previous chapter to install Alamofire in the application and open the xcworkspace file. Create a MainViewController class and make a get request to print the API data using Alamofire. // Do any additional setup after loading the view. print("Response.
Alamofire is built on top of NSURLSession, and is less lines of code to do REST interactions with (POST/GET/PUT/etc). It will get you "90%" of the way, but if you need to do super specialized network calls, you will need to use NSURLSession.
For Alamo 5 you have to use:
response.value
Try the following code, please:
switch response.result {
case .success(let value):
if let JSON = value as? [String: Any] {
let status = JSON["status"] as! String
print(status)
}
case .failure(let error): break
// error handling
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With