移动应用程序开发 | 第九讲-可选值和范型:Nothing Optiona...

第九次作业
作业一:完成下面的练习题
1. See if you can figure out what each of the following will print, if anything. If it doesn't print anything, what's the smallest change you could make to get it to print?

2. Take a look at the following code. It defines some structs that create a Person and a Song. Each Person has a name, a favoriteSong, and a favoriteKaraokeSong. But favoriteKaraokeSong is an optional, because not everyone likes karaoke. We’ve also created some example people for you.

Write a function to print out the favoriteKaraokeSong of the three instances of Person we created for you, using an if statement. The function should print out a message saying that they don't have a favorite karaoke song if they don't have one. Once you've done that, create some additional people using our Person struct, and call your function.
3. BE the Swift Compiler
Your job is to play Swift compiler and examine the following optional-using code to see if it will compile, or if it will error/crash because of the way optionals are used or not used. Take your time. Assume all the snippets run independently, and have no knowledge of each other.


作业二:完成Playgrounds App《继续构建App》剩下的章节