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

DAY 11

Structs, part two


As you’ve seen, structs let us combine individual pieces of data to make something new, then attach methods so we can manipulate that data.

Today you’re going to learn about some of the more advanced features of structs that make them more powerful, including static properties and access control – the art of stopping other parts of your code from meddling in places they ought not to be.

There’s a famous quote that is sadly anonymous, but I think it fits well here: “privacy is power – what people don’t know, they can’t ruin.” As you’ll see, the same is true in Swift: hiding access to certain properties and methods can actually make our code better, because there are fewer places able to access it.

As a reminder, both of these things are used extensively in SwiftUI, so it’s worth taking the time to master them now because they’ll be in use from our very first project onwards.

Today you have two tutorials to work through, where you’ll meet multiple levels of access control, and also the ability to create static properties and methods. Once you’ve watched each video and any optional extra reading you wanted, there’s a short test to help make sure you’ve understood what was taught.

  1. How to limit access to internal data using access control
  2. Static properties and methods
  3. Summary: Structs
  4. Checkpoint 6

That’s day 11 complete, so hopefully by now you know what to do: go and post about your progress online on Twitter, Facebook, Reddit, or whatever social media you like.

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!

Need help? Tweet me @twostraws!

 

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.