PlaylistUserDefaults is designed to help have students practice converting model objects to dictionaries and persisting data using UserDefaults.
Look over the README in the root folder of this repository
Start this project from Playlist (the version without persistence), not from scratch
- Show students the final product first so they know what they are working toward.
- Take a few minutes to go over the version without persistence and make sure everyone understands things like
prepare(for segue: UIStoryboardSegue, sender: Any?)
. - Have students look at UserDefaults documentation and discuss with each other how it works and what objects it can store. This should help them reinforce the idea that you cannot store your custom objects "as-is".
- Plan out the new methods you will need to store and load data.
- Go to your
Song
object and create a computed property that will convert it into a dictionary. - Create a failable initializer for your
Song
object that will take a dictionary and convert it into aSong
instance. - Repeat the last two steps for your
Playlist
object. - Fill out your
saveToPersistentStore()
function, referencing documentation for the UserDefaults functions. - Determine where in the project you need to call
saveToPersistentStore()
and add the call(s). - Fill out your
loadFromPersistentStore()
function, referencing documentation for the UserDefaults functions. - Determine where in the project to load your data, and call
loadFromPersistentStore()
. Everyone's app should work now.