Saving Data in iOS

May 31 2022 Swift 5.5, iOS 15, Xcode 13

Part 2: JSON

13. Saving On Device

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 12. Challenge: Decoding JSON Arrays Next episode: 14. JSON Encoding

Apple’s Bundle documentation

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.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

In this video, you’ll begin working with files in the user’s app Sandbox. Up until now you were decoding the JSON data from files in your app Bundle, that is, in files that were already added to your application prior to building your application binary.

print(Bundle.main.bundleURL)
print(FileManager.documentsDirectoryURL)
let temporaryDirectoryURL = FileManager.default.temporaryDirectory
print(temporaryDirectoryURL)
let tasksJSONURL = URL(fileURLWithPath: "PrioritizedTasks",
                       relativeTo: FileManager.documentsDirectoryURL).appendingPathExtension("json")
print((try? FileManager.default.contentsOfDirectory(atPath: FileManager.documentsDirectoryURL.path)) ?? [])