Handling Optionals

Open a new Swift playground. Create a Person class with three properties:

  1. name property whose type is String.
  2. favoriteColor property whose type is an optional String.
  3. favoriteMovie property whose type is an optional String.

Create a custom initializer where you set the name. Then, outside of the Person class, create an instance of Person and initialize it with your name. Set either the favoriteColor OR favoriteMovie property. Next, print out a description of the person's favorite things, being sure to properly handle the optionals beforehand. Also print out the optional property you didn't set and observe the result.

Black Diamond

Create a function that will print out a description of a person's favorite things, or say that the person doesn't like anything. This function should work properly whether or not the optional properties were set. Example printouts below:

Example 1: "John's favorite color is blue."
Example 2: "John's favorite movie is Star Wars."
Example 3: "John's favorite color is blue and his favorite movie is Star Wars."
Example 4: "John doesn't like anything."