[META] How to change datasource from static JSON file to API response?
Ludotrico opened this issue · 1 comments
Ludotrico commented
I see that there is a "stories.json" file that feeds all the models. I have already conformed the backend to return a JSON response identical to the "stories.json" file. However, I do not find it clear where/how I can populate the models.
This is how I usually transfrom JSON data into models using Alamofire:
func getStoryData(completion: @escaping(Result<IGStories, Error>) -> ()) {
DispatchQueue.global(qos: .userInitiated).async {
AF.request("http://127.0.0.1:8000/getStoryData/?userID=\(1)", method: .get, encoding: JSONEncoding.default)
.responseJSON { response in
if response.error == nil {
do {
let t = try JSONDecoder().decode(IGStories.self, from: response.data!)
print(t)
completion(.success(t))
} catch let error {
completion(.failure(error))
}
} else {
completion(.failure(response.error!))
}
}
}
}
Any insight?
boominadhaprakash commented
Hi @Ludotrico
Please refer this issue #85. We have already addressed your problem in this issue.