Expose property name to property wrapper

I've seen a common pattern among property wrappers that persist the property's value to use Strings as unique identifiers. Most recently with the introduction of @SceneStorage and @AppStorage in SwiftUI.

@AppStorage("preferredColorScheme") var preferredColorScheme: ColorScheme = .dark

I was wondering if it would be at all possible to expose the name of a property to its property wrapper. This would not only result in less verbosity, but also benefits from the compiler ensuring unique names across a specific scope. So the code from above would become

@AppStorage var preferredColorScheme: ColorScheme = .dark
17 Likes

It feels like a small yet quality-of-life feature👀 Is there any reason we shouldn’t introduce a new magic string #property for the wrappers?

6 Likes

100% agree, this would be useful for any kind of database wrappers, types that deal with codable, user defaults etc.