Clear unused UserDefaults key values from app

74 Views Asked by At

I am currently working on app which has been there since last few years. In the app, there is some cache stored as UserDefaults whose keys have now been removed from the code. So i want to clear those values to remove unnecessary memory. But, i do not want to remove the values stored in UserDefaults by some external package. So is there a way to achieve this?

I know we can fetch all keys by

UserDefaults.standard.dictionaryRepresentation().keys

But how to differentiate between the keys from the developer's side and those from packages?

1

There are 1 best solutions below

0
William Harris On

It would be nice if we could clear unnecessary cached values from UserDefaults without affecting values set by external packages.

While there's no direct way to differentiate between keys set by your code and keys set by packages, you can leverage the usage of versional control or prefix trick for managing keys.