欢迎光临散文网 会员登陆 & 注册

iOS移动应用程序开发 | 第六讲-结构体:Custom Types an...

2023-01-12 09:29 作者:陈鹏宇老师  | 我要投稿


01:12:51


第六次作业

作业一:完成下面的练习题

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.


作业二:完成Playgrounds App《开始构建App》第1~3章


iOS移动应用程序开发 | 第六讲-结构体:Custom Types an...的评论 (共 条)

分享到微博请遵守国家法律