p-x9 / AssociatedObject

🔗 Swift Macro for allowing variable declarations even in class extensions
MIT License
126 stars 3 forks source link

Add Support for custom Store Key #24

Closed mlch911 closed 7 months ago

mlch911 commented 7 months ago

In some cases, like inside an extension of a protocol, we can't add a static variable as the store key. This can provide custom store key by outside.

private var customKey = ""
extension Hashable {
    @AssociatedObject(.OBJC_ASSOCIATION_RETAIN_NONATOMIC, key: customKey)
    var text = ""
}
p-x9 commented 7 months ago

I thought it would be useful to be able to use custom keys regardless of how the keys are implemented(#28), so I am considering merging them.