Saving Data in iOS

May 31 2022 · Swift 5.5, iOS 15, Xcode 13

Part 2: JSON

15. Challenge: Encoding JSON Arrays

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 14. JSON Encoding Next episode: 16. Codable Hierarchies

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 15. Challenge: Encoding JSON Arrays

This course was originally recorded in April 2020. It has been reviewed and all content and materials updated as of November 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Time to save the array of prioritized tasks. Update the save prioritized task method to achieve this. Additionally, try to improve the output format of the JSON in your file, so it's easier to read. Have fun and see you back in a bit! (upbeat music) The first thing I did was update the method signature so it reflects that we are storing multiple tasks and not just one. Next up is storing the array of prioritized tasks. Yap, its that simple. You simply pass your prioritized tasks array and you're done! Almost, be sure to clean up the code that writes your data to the file in order to use the new constant name, as well as the URL you declare in the class, right at the end of the last video. Build and run your app, make sure you still have the prioritizedtasks.JSON file in the document directory, and try adding a task. Tada, you now have an array of prioritized tasks, but the formatting is making it difficult to really make out each task and their details. This is where the bonus objective comes in. You can tell Jason and Kuru that you want to use a pretty format. Add this line right after creating your encoder. If you run your app and create or delete a task now, you will notice the resulting file is much easier to read.