Let's download some data!!!! We've spend the last few videos setting up out list in preparation of having coin data to display. When we set up our Model (CoinModel), we made it conform to Codable so that we can decode it from JSON data. In this video, we will be downloading that data from the API, decoding it into CoinModels, and then displaying it in our list! The important thing to note in this video is the architecture that we are implementing. We are using MVVM (of course!) but also adding a "Data Service" layer that will handle logic for interacting with the API. This is very common in production apps to distinguish the (1) code in the ViewModel handles logic to update the View and (2) the code in the Service which handles logic to update the backend/database/api. Note: this architecture can be improved on even more by adding Protocols and Dependency Injection, but I haven't covered those just yet! :)
If you are not seeing coin data by the end of the video:
1. Check you are using the correct API
2. Add print() statements to catch errors and run it on a simulator
3. Ensure you set up the CoinModel correctly
*** LINKS:
- Downloadable Resources: https://www.swiftful-thinking.com/downloads
- CoinGecko API: https://www.coingecko.com/en/api
- CoinModel API: https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=true&price_change_percentage=24h
- Buy Me A Coffee: https://www.buymeacoffee.com/nicksarno
Next video: https://www.youtube.com/watch?v=pp5-ASYnY0o
Last video: https://www.youtube.com/watch?v=czjD-YIvLGU
69 Comments