Day 56
Day 56 ๊ด๋ จ
Project 11, part 4
After a few days of following along with me making a project, itโs time for you to step out of your comfort zone and start writing your own code. Once again, these are challenges Iโm setting you based on everything youโve learned so far, which means they are absolutely within your grasp if you set your mind to it.
Amy Morin, a social worker turned author, once said โthe more you practice tolerating discomfort, the more confidence you'll gain in your ability to accept new challenges.โ This is the underlying goal in all these challenges: giving you a little nudge to try something yourself, to figure out what works, and โ bluntly โ to screw up a few times before you figure out the right solution.
There is value in getting things right, but thereโs just as much value in getting things wrong. Embrace that โ learn to tolerate the discomfort that goes hand-in-hand with writing fresh code yourself โ and youโll be a great developer.
Today you should work through the wrap up chapter for project 11, complete its review, then work through all three of its challenges.
Bookworm: Wrap up
Bookworm: Wrap up
Congratulations on finishing another SwiftUI project! With technologies like SwiftData at your side, youโre now capable of building some serious apps that interact with the user and โ most importantly โ remember what they entered. Although we only scratched the surface or SwiftData, itโs capable of a lot more and I expect Apple to keep expanding the link between SwiftData and SwiftUI in future updates. In the meantime, the very next project focuses deeply on SwiftData โ thereโs lots to explore!
As for the other things you learned, youโve now even more of SwiftUIโs property wrappers, and I hope youโre getting a sense for which one to choose and when. @Binding
is particularly useful when building custom UI components, because its ability to share data between views is just so useful.
Thereโs one last thing Iโd like to leave you with, and itโs something you might not even have noticed. When we built a star rating component, we created something that became a user-interactive control just like Button
and Slider
. However, we didnโt stop to consider how it works with accessibility and thatโs a problem: Button
, Slider
, and others work great of the box, but as soon as we start creating our own components we need to step in and do that work ourselves.
Building apps that are accessible for everyone is something everyone needs to take seriously, which is why Iโve dedicated a whole technique project to it in the future โ weโre going to be looking back at the previous projects weโve made and seeing how we can improve them.
Anyway, first things first โ you have a new review and some challenges. Good luck!
Review what you learned
Anyone can sit through a tutorial, but it takes actual work to remember what was taught. Itโs my job to make sure you take as much from these tutorials as possible, so Iโve prepared a short review to help you check your learning.
Click here to review what you learned in this project.
Challenge
One of the best ways to learn is to write your own code as often as possible, so here are three ways you should try extending this app to make sure you fully understand whatโs going on.
- Right now itโs possible to select no title, author, or genre for books, which causes a problem for the detail view. Please fix this, either by forcing defaults, validating the form, or showing a default picture for unknown genres โ you can choose.
- Modify
ContentView
so that books rated as 1 star are highlighted somehow, such as having their name shown in red. - Add a new โdateโ attribute to the Book class, assigning
Date.now
to it so it gets the current date and time, then format that nicely somewhere inDetailView
.
Bookworm: Wrap up - Additional
Share something online about what you learned, or how you might use it in the future โ do you like SwiftData? Are you keen to create more custom user interface components? Tell folks โ stay accountable!