Exploring Potential for async Property Wrappers in Swift

Hi everyone,

Currently, property wrappers in Swift provide great abstractions for common tasks like validation, caching, and data binding. However, I’ve been wondering whether there’s a way to introduce async property wrappers—something that allows asynchronous actions or network requests directly in a property’s getter or setter.
How do you think this could fit into Swift? Would it make code cleaner, or introduce complexity that could complicate debugging and performance?

Thanks for any help!

1 Like

Hi, you can use async (and throwing) property getters since Swift 5.5. I don't think a PropertyWrapper would add much value.

var isSynced: Bool {
    get async {
       await database?.isEntitySynced(self) ?? false
   }
}

Usage: hackingwithswift.com

I believe the author is asking here about property wrappers providing their wrappedValue or projectedValue as a computed property with such getter.

IMHO while a nice addition to property wrappers, property wrappers themselves currently feel somewhat like a misfeature in the presence of macros. Not sure if they're worth allocating resources for.

You are probably right, sorry.