sindresorhus / Defaults

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

New init with default parameter that accepts another key #155

Closed Maschina closed 5 months ago

Maschina commented 6 months ago

Proposal to create a key with another key as default value. This can be useful if you want to change the name of the key, but still provide support to migrate from the previous key name.

sindresorhus commented 6 months ago

It would be better if it accepted a string name as the default key (or previousName as a better name), since then you don't have to use two Defaults.Key. You just rename the existing Defaults.Key property name and then refer to the old UserDefaults name in the previousName parameter. That being said, I'm not even sure this init carries its own weight as you can generally just keep the UserDefaults string name while renaming the Defaults.Key property. I do that all the time. Much easier.