Skip to main content

Day 56

About 3 minSwiftcrashcoursepaul-hudsonswiftswiftuihacking-with-swiftxcodeappstore

Day 56 ๊ด€๋ จ


Project 11, part 4

100 Days of SwiftUI - 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
100 Days of SwiftUI - Day 56 - 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.open in new window

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.

  1. 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.
  2. Modify ContentView so that books rated as 1 star are highlighted somehow, such as having their name shown in red.
  3. 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 in DetailView.

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!


์ด์ฐฌํฌ (MarkiiimarK)
Never Stop Learning.