GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

DAY 80

Project 16, part 2


Today you’re going to tackle a tricky concept in the form of Swift’s Result type, but to balance things out we’re also going to cover two easier ones too so hopefully you don’t find today too much work.

Swift’s Result type is designed to solve the problem when you know thing A might be true or thing B might be true, but exactly one can be true at any given time. If you imagine those as Boolean properties, then each has two states (true and false), but together they have four states:

  1. A is false and B is false
  2. A is true and B is false
  3. A is false and B is true
  4. A is true and B is true

If you know for sure that options 1 and 4 are never possible – that either A or B must be true but they can’t both be true – then you can immediately halve the complexity of your logic.

American author Ursula K Le Guin once said that “the only thing that makes life possible is permanent, intolerable uncertainty; not knowing what comes next.” The absolute opposite is true of good software: the more certainty we can enforce and the more constraints we can apply, the safer our code is and the more work the Swift compiler can do on our behalf.

So, although Result requires you to think about escaping closures being passed in as parameters, the pay off is smarter, simpler, safer good – totally worth it.

Today you have three topics to work through, in which you’ll learn about Result, image interpolation, and context menus.

How can this day be improved?

Great job on finishing another day! If you still have questions about what you learned, please send them in using this form – I'll do my best to address the most common problems in the next course update. Thank you!

Now share your progress…

If you use Twitter, the button below will prepare a tweet saying you completed today, along with a celebratory graphic, the URL to this page, and the challenge hashtag. Don't worry – it won't be sent until you confirm on Twitter!

Alternatively, copy and paste the text below to your preferred social network - I'm @twostraws on Mastodon.social, Bluesky, and Threads.

🎉 I just finished Day 80 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/80 via @twostraws

Need help? Tweet me @twostraws!

 

Hacking with Swift is sponsored by RevenueCat.

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

Click to save your free spot now

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

100 Days of SwiftUI


The 100 Days of SwiftUI is a free collection of videos, tutorials, tests, and more to help you learn SwiftUI faster. Click here to learn more, or watch the video below.

Back to 100 Days of SwiftUI

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.