From the course: iOS App Development: RESTful Web Services
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Codable for dictionaries - iOS Tutorial
From the course: iOS App Development: RESTful Web Services
Codable for dictionaries
- [Instructor] So we've seen that arrays are handled fine by Codable. Data being passed down with multiple instances is no problem. Also, dictionaries can be implemented and handled by Codable as well, as long as the key value pairs in the dictionary implement Codable. So for something like, a string for the key and an int for the value, that's fine, they have default implementations of the Codable protocol. So that means dictionaries not only can be encoded and decoded, but also classes can have properties that are dictionaries, again, as long as the keys and values implement Codable. In fact, properties can be anything that implements Codable. So let's look at an example of how dictionaries can be used as a property, and handled by Codable. So first thing we're going to do, is go into our class and add a new property that's a dictionary. We'll make ours a dictionary that's a string for the key, and an int for the value. Now we have to add this new property name that we defined on…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.