iOS移動應(yīng)用程序開發(fā) | 第六講-結(jié)構(gòu)體:Custom Types an...

第六次作業(yè)
作業(yè)一:完成下面的練習題
1.

(i) Using your knowledge of initializers and structures, write a custom initializer for the GarlicBread struct that sets the vegan Bool to false (the chef isn't yet ready to offer vegan garlic bread, but plans to in the future) and accepts a strength value. The chef would also like the initializer to print out a message that states “New Garlic Bread of strength x created!" each time a GarlicBread is initialized.
(ii) The chef would like to update the struct to include an integer to represent how spicy the GarlicBread is, and would like the option to initialize a GarlicBread in any one of the following ways:
- With no parameters (a strength value of 1, a spicy value of 0, not vegan)
- With only a strength parameter passed in (a spicy value of 0, not vegan)
- With a strength parameter and a spicy parameter passed in (not vegan)
- With a strength parameter, a spicy parameter, and the vegan status passed in
Please code as many initializers for GarlicBread as are necessary to support this.
2. Which of the following examples of a static property are valid? If it’s not valid, explain why.

3. See if you can assemble the magnets into some useful code. Be careful; a few extra magnets got mixed in, and some might get used more than once.

作業(yè)二:完成Playgrounds App《開始構(gòu)建App》第1~3章

