sindresorhus / Defaults

💾 Swifty and modern UserDefaults
https://swiftpackageindex.com/sindresorhus/Defaults/documentation/defaults
MIT License
1.93k stars 115 forks source link

My Defaults.Key is dynamically created, how to use the @Default syntax. #179

Closed JRJian closed 1 month ago

JRJian commented 1 month ago

let selectedCalendarIDs = Defaults.Key<[String]>("\(widget.id)_selectedCalendarIDs", default: [])

How to use my create key? @Default(????) var selectedCalendarIDs

sindresorhus commented 1 month ago

Same as how you would create a @State dynamically, you assign the underscored storage (for example, self._someKeyName) in your initializer.

JRJian commented 1 month ago

Thanks, got it!