UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

2      

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.

2      

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.

2      

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.

DispatchQueue.main.async{ 
doYourStuffHere() 
}

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.

https://www.hackingwithswift.com/forums/100-days-of-swiftui/publishing-changes-from-background-threads-is-not-allowed-day-60-friendface-part1/12971

2      

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.

2      

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!

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.