Is there a way to basically clone all the keys and...
# touchlab-tools
l
Is there a way to basically clone all the keys and values of a MultiplatformSettings to another one, e.g. duplicate the underlying files? My goal is to basically have all minus one of the keys, and copying key-by-key would be a lot of code
r
There's no built-in for this. The library does all its work by delegating to platform-specific APIs, so you could probably hack something together, but it'd be per-platform via the platform APIs, not via Multiplatform Settings
l
That would actually be fine, I just need to run this for iOS
Turns out the solution was fairly easy 🙏 the gist being:
Copy code
val newDelegate = NSUserDefaults(suiteName = NEW)
val migrationKey = "didMigrate"
// Emptying the old delegate and checking for its size does not work, so create a migrationKey.
if (!destination.boolForKey(migrationKey)) {
  val source = NSUserDefaults(suiteName = OLD)
  for ((key, value) in source.dictionaryRepresentation()) {
    destination.setValue(value, forKey = key as String)
  }
  destination.setBool(true, migrationKey)
}