Skip to content

Instantly share code, notes, and snippets.

@simrandotdev
Last active November 6, 2018 17:35
Show Gist options
  • Save simrandotdev/9170f494cc4812064e60849f5e0c6383 to your computer and use it in GitHub Desktop.
Save simrandotdev/9170f494cc4812064e60849f5e0c6383 to your computer and use it in GitHub Desktop.
AccResponse.swift
extension Data {
// Converts JSON data to specified object
func fromJsonData<T : Decodable>(to type: T.Type) throws -> T {
return try JSONDecoder().decode(T.self, from: self)
}
}
struct AccResponse : Codable {
let acc: Acc
let state: String
}
struct Acc : Codable {
let activeFlag: Int
let birthDate: String
let displayName: String
let emailAddress: String
let enableFlag: Int
let infos: Infos
let faceBookAccount: String
let gender: String
let mobileNo: String
let userName: String
}
struct Infos : Codable {
let allAddInfos: [Infos]
}
struct Info : Codable {
let addInfoId: Int
let addInfoValue: String
}
// After you add all this code, in the Alamofire call where you get the response data object which contains your JSON
// Just run the following code
val accResponse = responseData.fromJsonData(AccResponse.self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment