Implementing a data manager class to read data from a .plist file
You have added a .plist
file, ExploreData.plist
, to your project containing the cuisine data, and you have created a structure, ExploreItem
, that can store details of each cuisine. Now, you need to create a new class, ExploreDataManager
, that can read the data in the .plist
file and store it in an array of ExploreItem
instances. You’ll refer to this class as a data manager class. Follow these steps:
- Right-click on the Model folder and select New File.
- iOS should already be selected. Choose Swift File, then click Next.
- Name the file
ExploreDataManager
and then click Create to display its contents in the Editor area. - Type the following code in the file to declare the
ExploreDataManager
class:class ExploreDataManager { }
- Type in the following code between the curly braces. This implements a method,
loadData()
, which will read the contents of theExploreData.plist...