Thread 2, Day 13 - Friday, February 3, 2023
Agenda
- Finding Square Roots
- You can review the history of commits for this project to understand the simplest possible flow for handling user input that is expected to be numeric.
- We must take a
String
, convert it to an optionalDouble
, then unwrap the optional to a regularDouble
so we can do arithmetic with the value, and finally, produceString
output again:flowchart LR id1["Step 1\nString"] --> id2["Step 2\nDouble?"] id2 --> id3["Step 3\nDouble"] id3 --> id4["Step 4\nString"]
- You can review the history of commits for this project to understand the simplest possible flow for handling user input that is expected to be numeric.
- Share the Bill: Opportunities for Further Abstraction
- A complete example that ties together all concepts we have learned so far in this module
- Optionally, you can review how it was built, step by step
- In the list of commits, click the commit details badge to see what changed within that specific commit:
- Please fork and clone the repository for this app now
- With a partner, review the code within the
body
property- What opportunities for eliminating repetitive code do you see?
- Let's improve this now...
NoteHere is the video from this discussion in class – how to apply abstraction.
- With a partner, review the code within the
- A complete example that ties together all concepts we have learned so far in this module
- Share the Bill: Add a Second Tab to Show History
- Data to be saved within an app should be created in one location only
- Put another way, a given piece of data must have just one single source of truth
- Currently this occurs with the
@State
property wrapper - How, though, can we share data between screens?
- That is where the
@Binding
property wrapper is useful- In brief:
flowchart TD id1["App Entry Point\n@State"] --> id2["Screen 1\n@Binding"] id1 --> id3["Screen 2\n@Binding"]
- Let's examine this together now...
NoteHere is the video from this discussion in class – how to share data between screens using @Binding
- In brief:
- Data to be saved within an app should be created in one location only
- End-of-module Task: Make an Interactive App
To-do items
Before our next class...