Custom Properties

PART 1

  1. Make a constant called currentYear that is an integer equal to the current year (e.g. 2016).
  2. Create a Person struct with properties for first name as a String, last name as a String, and year of birth as an Int.
  3. Create an instance of the Person struct
  4. Print out the instance's birth year
  5. Print out its first and last name

PART 2

  1. Add a computed property for age to the Person struct
  2. Implement a getter for age. The getter should calculate and return the person's age based on the current year and the person's year of birth. (Hint: Look up getters in the Swift programming guide or in documentation).
  3. Implement a setter for age. The setter should update the year of birth based on the age and current year. (Hint: look up setters).
  4. Print out the person's age
  5. Update their age and then print their new year of birth.

Black Diamond

Change your currentYear constant so that instead of being a hard-coded, static year, it uses NSDateComponents to get the actual current year anytime it runs. Documentation should help you out.