From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Read JSON files

Read JSON files

- [Instructor] A very popular data file is JSON. Apple uses it in Xcode and for remote notifications. As developers, we may need to read JSON files with our code, and translate them into usable objects in Swift. With the JSONDecoder, it's easier than pronouncing JSON, or is it JSON? I'll start with this skeleton app I made. On lines eight through 18, you'll see some JSON code. I enclosed it with the new Swift triple quote string delimiters for multi-line text. For the coders to work this is supposed to be of type Data, which I can set up with the data method, encoding it to UTF8. Now I'm not going to give you a full lesson on JSON, but here's a brief summary for the uninitiated. This is a collection of objects, with a string key and a value, much like a dictionary in Swift. The braces encase the object, the first string is the key, and then we have a value. Values can be of most basic data types, such as strings, integers, floats, bools, and doubles. You can also use arrays like I did…

Contents