Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSC 214

Homework Assignment #3

2022

In Sink or Swim the user has to guess whether or not a hidden item floats . It requires 2 Views as shown . Your model must conform to the ObservableObject protocol and publishes a result string and a property of type Item (struct).

@Published var result = ""

@Published var item = Item(image: "", floats: false)

Add a function newGame(itFloats: Bool) in which you set item to a random element from an 8 element items array (hint: shuffle). Then set result to "You Win" if itFloats matches the item's floats element or "You Lose" otherwise.

Section 1 [20 points]

Create a new ItemView as shown below with 2 Text objects and a button. The top Text displays your model's result string and the center string the model's image string (emoji). To make the model available in your ItemView declare it here as

EnvironmentObject:

@EnvironmentObject var model: SinkOrSwim

Your model will now stay updated in the ItemView and its properties (i.e. model.image) can be accessed via dot syntax.

Section 2 [20 points]

Create the ContentView (top) layout as shown. For navigation use a NavigationView that shows the string "Sink or Swim" as navigationBarTitle . Add 2 NavigationLinks (Sinks, Swims) each of which execute the model's newGame(itFloats:) function . The question mark in the center is a static Text .

Still in the ContentView add your model like so:

@StateObject private var model = SinkOrSwim()

Then add an environmentObject modier to your NavigationView to make the model available to your ItemView:

.environmentObject(model)

Section 4 [20 points]

The user expects the "Try Again" button in the ItemView to return them to the main View. In order to make that happen add the following somewhat unusual looking environment property in your ItemView:

@Environment (\.dismiss) private var dismiss

You can now simply call dismiss() in your button action. Lastly add a                           navigationBarBackButtonHidden modifier to your ItemView's main stack to hide the NavigationView's back button at the top since that is no longer needed:

.navigationBarBackButtonHidden(true)

Section 3 [20 points]

Add an app icon filling all slots.

Section 4 [10 points]

Set the background color for both of your views to .orange by embedding your Views in a ZStack and adding a Color element with a edgesIgnoringSafeArea modifier at its bottom:

Color.orange

.edgesIgnoringSafeArea([.all])

Section 6 [10 points]

Your project's git repo has a commit depth of minimally 6 as it is a continuation of your previous assignment. This holds true for all homework assignments.

Hand In

1.   create a submission directory named after your user id but add "-hw-x" for the

specic assignment (e .g . jsmith-hw-3" for homework or jsmith-p-3" for projects)

2.    fill out a copy of the course ReadMe template and add it to submission directory

3.    add your full project directory to the submission directory, not just the project le .

4.    your project's app's bundle id starts with "com ." and your user id (e .g .com.jsmith)

5.   zip up the submission directory and submit it to Blackboard.

Notes:

Never email projects. The only way anything gets graded is through Blackboard.

Submit early and submit often .

You are not allowed to host your solutions in a public account (e .g . GitHub) . Doing so

constitutes a violation of the Academic Honesty Policy which has severe

repercussions .

Remember: Late submissions cannot be accepted. Please don't ask.