drawRect / Instagram_Stories

Inspired by Instagram Stories functionality. This source is similar to Instagram Stories, which is having both image and video support.
MIT License
414 stars 76 forks source link

[META] How to change datasource from static JSON file to API response? #108

Closed Ludotrico closed 3 years ago

Ludotrico commented 3 years ago

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 3 years ago

Hi @Ludotrico

Please refer this issue https://github.com/drawRect/Instagram_Stories/issues/85. We have already addressed your problem in this issue.