Failable Initializers

Example Dictionary:

let workingDictionary = ["nameKey" : "Derek", "ageKey": 28, "favMovieKey" : "Zoolander"]
let brokenDictionary = ["nameKey" : "Steve", "ageKey": 2]

PART 1

  1. Make a person class with name, age, and favoriteMovie properties
  2. init the class with a dictionary of type string:anyobject.
  3. Test this to make sure that it works

PART 2

  1. Read about Failable Initializers
  2. Use a guard statement to handle missing dictionary values
  3. If a value is missing, don't init the person and instead return nil

Black Diamond

Open your Journal project from yesterday. Create a function that will convert your Entry objects into dictionaries. Use this to encode all of the Entry objects stored in your sharedInstance as dictionaries, then print the result.