I made a post request using Alamofire. This is my code to fetch data from server using an endpoint:
Alamofire.request("http://192.168.80.21:3204/api/auth/signin", method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: nil).responseJSON {
response in
switch response.result {
case .success(let value):
let json = JSON(value)
print(json)
break
case .failure(let error):
print("Error :- \(error)")
}
}
}
And this is the data i get from the server:
{
"accessToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NTIsInJvbGUiOjEsImlhdCI6MTYwMzg2ODUxNCwiZXhwIjoxNjAzOTU0OTE0fQ.y68w8XQfqFZDVgaxiuFuVCOqaI5e5vZ-SfoDB_Ctxro",
"role" : "admin",
"auth" : true
}
I want to save the response to UserDefault for further use. Help me to save the data to Userdefault and retrieve and print data.