Mini-exercises

  1. Make an optional String called myFavoriteSong. If you have a favorite song, set it to a string representing that song. If you have more than one favorite song or no favorite, set the optional to nil.
  2. Create a constant called parsedInt and set it equal to Int("10") which tries to parse the string 10 and convert it to an Int. Check the type of parsedInt using Option-Click. Why is it an optional?
  3. Change the string being parsed in the above exercise to a non-integer (try dog

for example). What does parsedInt equal now?

results matching ""

    No results matching ""