Summary

This chapter was all about adding a small, simple feature to an existing app. We added the ability to load real data from an API. You saw that networking is made pretty straightforward by Apple with URLSession and data tasks. You also learned that this class abstracts away some very complex behavior regarding multithreading, so your apps remain responsive while data is loaded from the network.

Once you knew how to load data from the network, you learned about JSON and how you can read values from a JSON response in Swift. Working with JSON is somewhat tedious, and many developers opt to use a library, such as SwiftyJSON, to make their lives a bit easier.

Next, you implemented a helper struct for networking and updated the Core Data model so we could store ratings for movies. Once all this was done, you could finally see how multithreading works in the context of this app. This wasn't everything we needed to do though. You learned about ATS and how it keeps your users secure. You also learned that you sometimes are needed to circumvent ATS and how you can achieve this.

Even though the feature itself wasn't very complex or big, the concepts and theory involved can be quite overwhelming. You suddenly had to deal with code that would be executed asynchronously, in the future. And not just that, the code even used multiple threads to make sure that their performance was optimal. The concepts of multithreading and asynchronous programming are arguably two of the more complex aspects of programming. Practice them a lot and try to remember that any time you're passing around a closure, you could be writing some asynchronous code that gets executed on a different thread.

Now that our list of movies is updated with data from the Web, let's take it one step further. We can use background fetching to make sure that we always fetch the most up-to-date information for our movies and update them without the user even noticing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.248.47