100 Days of SwiftUI Day 80

100 Days of SwiftUI – Day 80

We’ve arrived at day 80 of the 100 Days of SwiftUI. After today, we enter the final stretch of this course we’ll have completed a whopping 80% of the course. It’s been quite a journey and a difficult one at that, but we know what we’re doing it for.

Yesterday, we started on our new “Hot Prospects” app. We’ll continue this for the coming days. Let’s dive in!

Manually publishing ObservableObject changes in SwiftUI

Up until now, we’ve used SwiftUI’s @Published property to automatically announce any changes to our properties. However, if we want some more, fine grain control, that’s possible as well.

Classes that conform to the ObservableObject protocol can use SwiftUI’s @Published property wrapper to automatically announce changes to properties, so that any views using the object get their body property reinvoked and stay in sync with their data. That works really well a lot of the time, but sometimes you want a little more control and SwiftUI’s solution is called objectWillChange.

Every class that conforms to ObservableObject automatically gains a property called objectWillChange. This is a publisher, which means it does the same job as the @Published property wrapper: it notifies any views that are observing that object that something important has changed. As its name implies, this publisher should be triggered immediately before we make our change, which allows SwiftUI to examine the state of our UI and prepare for animation changes.

Hacking with Swift, Paul Hudson (@twostraws)

Understanding Swift’s Result type

The Result type is a type that contains either some value or an error. This is comparable to an optional, which either contains a value or is empty. Check out Paul’s article on how we use the Result type and why they’re very useful.

Controlling image interpolation in SwiftUI

Image Interpolation happens when we stretch content larger than its original size. The performance hit we take is, especially on modern devices, not noticeable, due to the vast amounts of computing power they have. There’s a catch though, which Paul explains in his article on image interpolation.

What happens if you make a SwiftUI Image view that stretches its content to be larger than its original size? By default, we get image interpolation, which is where iOS blends the pixels so smoothly you might not even realize they have been stretched at all. There’s a performance cost to this of course, but most of the time it’s not worth worrying about.

Hacking with Swift, Paul Hudson (@twostraws)

Wrap up

That’s it for day 80! As we arrive at the final stretch of the course, keep yourself energised and keep going at it. I recommend looping over large parts of the course after you’ve finished to further solidify your knowledge and keep practicing. That’s my plan at least! For now, it’s time to recharge for tomorrow. Until then!

Darryl

Hi! My name is Darryl and this is my personal blog where I write about my journey as I learn programming! You'll also find articles about other things that interest me including games, tech and anime.

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

100 Days of SwiftUI – Day 35

100 Days of SwiftUI – Day 32

100 Days of SwiftUI – Day 15 – Consolidation

100 Days of SwiftUI – Day 51