From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Property wrappers

Property wrappers

- [Instructor] If you've worked with a Combine, or Swift UI frameworks, you've probably run some strange identifiers like observed property and state. These are property wrappers, which increase the power of Swift properties, by making standard ways of handling certain kinds of properties. Let's learn how you can use property wrappers in your applications. In the exercise file, I have a playground with struct for identifying a pizza. It has two toppings and a diameter. Now, when we talk about cheese, we're really talking about mozzarella cheese, so I want any generic mention of cheese in a pizza to be translated to mozzarella. I can make some setters and getters to do this, but I'd have to make them for both toppings one and two. It'd be nice to have something like a protocol that tells the property to act a certain way anywhere I declare it. That's what property wrappers do. You define a property wrapper by the…

Contents