Property Wrappers

UserDefaults and Property Wrappers

Published on


**Important Note**

Soon after I published this article, Christian Tietze wrote a fair criticism of this idea here.

Once you understand how property wrappers work, you can use this article to apply it to user defaults. The main idea is that property wrappers allow you to store your values differently and even externally. That said, you may or may not want to implement this in a real app. I recommend you read this article first, and then go back to Christian’s to see more downsides of this idea other than the ones I mentioned below.


Understanding Property Wrappers in Swift

Published on

Swift 5.1 introduced a sleuth of wonderful features, and amongst them, there’s one that is essential for SwiftUI: Property Wrappers. Property wrappers are a powerful feature in Swift that allow you to wrap behavior along with properties. This allows us to do some interesting things. If you have seen SwiftUI, you’ve seen the @State “keyword”, and you know that it allows you to modify structs. This is possible thanks to the behavior “wrapped” within properties marked with it.