WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Day 46 Completed

Forums > 100 Days of SwiftUI

Day 31 Completed

I am really enjoying the little projects being games. It is a lot of fun to create them and then spend some time extending and modifying them. For the Word Scramble I added animating when restart re-initialises the screen, alternating row coloring to the list of used words and spent a while trying different algorithms for the score.


Day 34 Completed

It's been quite a while since I have put in the hard work on this course. I am so glad that I came back to it and have renewed my commitment to complete it. The days slip by so easily and I find myself looking at my last progress post being weeks ago - and feeling ashamed by it.

Getting to the end of day 34 was pretty hard since I had lost momentum and many of the fine details of the last half dozen lectures had slipped through my memory. So I went back a bit and reviewed the lectures again and then I managed to complete the project.

In my first attempt I used the parallel arrays design pattern to store state variables for each of the flags' rotation and opacity; then used the ForEach index of the selected flag to modify the value of the appropriate element in the parallel array - within an explicit animation block This worked fine and seemed to fit with the way I tend to think about this kind of problem. However, when I went back and looked at the solution hint I realised that I had missed the learning objective - it took quite a bit of mind bending until the intended solution clicked into place.


Day 38 Completed

The iExpense challenge was certainly difficult and even though I got the functionality working I'm left with a nasty feeling that my code isn't particularly good. It doesn't seem threadsafe. I'm thinking of a situation where my list is being filled from incoming network data (a background thread); so the indexes of the list are changing. At the same time the user is selecting items and deleting them. I have done this myself in the Apple mail app.

I used a filter in the view code to separate the personal and business expenses. I am pretty sure this means that the filter provides a copy of the data every time I access it since I used a computed property. Then when onDelete gets triggered I grab another copy of the filtered list of expenses so that I can find the correct items to delete from the list of expenses (searching using the id property).

I think a problem will happen when the List contents get updated by the background thread immediately after onDelete starting. In this case the IndexSet may contain old (incorrect) indexes and I'll end up deleting this wrong data.


You figured it out and got it working, great job! You're already thinking ahead and dealing with the issue you mentioned is covered in Day 61.

In short, anything coming "up" from other parts of the code to update the UI have to be handed off to the UI or "main" thread so you don't end up with thread collisions, race conditions, dead locks, etc.

Anything that you're doing in background or as a result of callbacks or closures (or non-ui events) should be handed off in a GrandCentral Dispatch call.


It's just a way to say "Hey, User Interface, here's that stuff you wanted me to get for you," then let him paint his own house, his way, and just thank you for delivering the paint.



Day 42 Completed

I think project 8 is my favourite so far. The functionality I am able to use now really feels like enough to make some useful applications.


Day 46 Completed

Project 9 was very interesting - although I can't think of where I'll use these techniques. Another fairly straight forward project - this is testament to the structure of the course so far. I even found the explanation of why withAnimation needs special code understandable :-) woohoo!


Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.