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
11 Likes
Terms of Service

Privacy Policy

Cookie Policy