Loading and saving JSON data
Now that you have modified the JournalEntry class to conform to the Codable protocol, you are ready to implement loading data from and saving data to JSON files.
To make it easier for you to work with JSON files, Apple provides JSONDecoder and JSONEncoder classes.
A JSONDecoder instance decodes instances of a data type from JSON objects, and you will use it when loading files from your device storage.
To learn more about JSONDecoder, see https://developer.apple.com/documentation/foundation/jsondecoder.
A JSONEncoder instance encodes instances of a data type to JSON objects, and you will use it when saving files to your device storage.
To learn more about JSONEncoder, see https://developer.apple.com/documentation/foundation/jsonencoder.
You’ll now implement the methods to load data from a file and save data to a file in the SharedData class. Follow these steps:
- In the Project navigator, click...