A small Swift Package that is wrapper around UserDefaults that allows the clients to use an enum
as key.
The wrapper exposes a cleanup function that removes unused keys, providing a sort of self cleaning functionality as the enum
values change as the app evolves.
enum Key: String {
case tutorialShown
case notificationShown
}
defaults.cleanup(Key.self)
defaults.set(true, forKey: Key.tutorialShown)
defaults.set(true, forKey: Key.notificationShown)
If case notificationShown
is removed, then the next time defaults.cleanup(Key.self)
runs, the value will be removed from UserDefaults.
Always use the same enum, using a different one for cleanup() will cause all the other values to be deleted.