In this lab, students will learn how to create navigation views and navigation bars in SwiftUI. They will practice passing data between different views and explore the usage of @State, @Binding, and @ObservableObject for managing state and updating views.
Instructions:
Create a new Swift playground or Xcode project to complete the lab tasks.
Follow the step-by-step instructions for each task below.
Write your code in a clear and organized manner, following best practices.
Requirements:
Xcode (latest version)
Basic knowledge of SwiftUI syntax and views
Tasks:
Task 1: Creating Navigation Views
Design a SwiftUI View that serves as the main entry point of the app.
Implement a navigation view with a navigation bar and a title for the main view.
Add a button to navigate to a second view.
Task 2: Passing Data Between Views
Create a second SwiftUI View to display detailed information.
Pass data from the main view to the second view when the button is tapped.
Display the received data in the second view.
Task 3: Using @State
In the main view, use @State to manage a variable that changes the view's appearance.
Implement a button in the main view to toggle the state variable and observe the UI update.
Task 4: Using @Binding
Create a custom SwiftUI View that contains a text field and a button.
Use @Binding to allow the parent view to modify the text field value.
Update the main view to include this custom view and showcase the two-way binding.
Task 5: Using @ObservableObject
Define an ObservableObject class with a published property to represent data.
In the main view, create an instance of the ObservableObject class and observe the data change.
Implement a button in the main view to update the data and see the UI reflect the changes.
Submission Guidelines:
Create new repository name it as "iOS-Developemnt-Bootcamp-July-2023-Week-2-Day-3-Lab".
Upload your project files to the repo you just created.
Submit your project repo link as comment down below.
Grading Criteria:
Your lab assignment will be graded based on the following criteria:
Correctness and completion of tasks (50%)
Code quality, readability, and adherence to best practices (30%)
Proper implementation of SwiftUI navigation and data passing (20%)
Additional Notes:
You may ask the lab instructor for assistance during lab hours.
Avoid plagiarism; write the code yourself.
Late submissions will not be accepted without prior approval.
Deadline:
Submit your completed lab assignment prior start of next session.
Objective:
In this lab, students will learn how to create navigation views and navigation bars in SwiftUI. They will practice passing data between different views and explore the usage of
@State
,@Binding
, and@ObservableObject
for managing state and updating views.Instructions:
Requirements:
Tasks:
Task 1: Creating Navigation Views
Task 2: Passing Data Between Views
Task 3: Using @State
@State
to manage a variable that changes the view's appearance.Task 4: Using @Binding
@Binding
to allow the parent view to modify the text field value.Task 5: Using @ObservableObject
ObservableObject
class with a published property to represent data.ObservableObject
class and observe the data change.Submission Guidelines:
Grading Criteria:
Your lab assignment will be graded based on the following criteria:
Additional Notes:
Deadline:
Submit your completed lab assignment prior start of next session.