Creating a singleton
At present, when you add new journal entries to your app, they will appear on the Journal List screen, but when you switch to the Map screen, the newly added journal entries are not present. This is because the MapViewController
instance does not have access to the journalEntries
array in the JournalListViewcontroller
instance. To solve this issue, you’ll create a new singleton to store your app data. A singleton is created once and then referenced throughout your app. This means that the JournalListViewController
class and the MapViewController
class will be getting their data from a single source.
For more information on singletons, see https://developer.apple.com/documentation/swift/managing-a-shared-resource-using-a-singleton.
You will create a singleton named SharedData
and configure the JournalListViewController
and MapViewController
classes to use it. Follow these steps:
- In the Project navigator, move the Model group...