Module Outline

Use the following resources and work with your mentor to master the objectives for this module. Practice by completing the Mini-Project, Project, and Challenges.

Objectives

Required Preclass Resources

Lesson Video

Preclass Videos

Video Challenges

  • Add Properties

    Add some extra properties to the model object. Try adding properties of different types. See if you can run into a type that doesn't conform to Codable.

  • Change from JSONEncoder to a PropertyListEncoder

    After using the PropertyListEncoder to encode your model object, print out the encoded data string and compare the differences to the JSONEncoder string.

Stretch Problem

    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.

  • Hint
  • Solution

Guided Project

    PlaylistCodable

    PlaylistCodable is designed to introduce students to the Codable protocol.

Project

  • Journal

    Students will build a simple Journal app to practice MVC separation, protocols, master-detail interfaces, table views, and persistence.

    Journal is an excellent app to practice basic Cocoa Touch princples and design patterns. Students are encouraged to repeat building Journal regularly until the principles and patterns are internalized and the student can build Journal without a guide.

    ReadMe

Mastery Review

Module 9 - Persistence using Codable
  • Expand all
  • Collapse all
  • Failable Initializers stretch problem
  • Challenges
    • Add Properties objective challenge
    • Change from JSONEncoder to a PropertyListEncoder objective challenge
  • PlaylistCodable guided project