dimanche 28 février 2021

Get all KeyPaths for an Object

Is there a way in Swift 5 to iterate over all keypaths? I'm aware Mirror will give you string representations of the keys, but I can't use setValue as my objects are not inherited from NSObject and several values are not @objc compatible. I am attempting to do something like the below (pseudo coded):

func overwrite(source:T, overwrite:T) {
  for keypath in overwrite.allKeypaths() {
    source[keyPath: keyPath] = overwrite[keyPath: keyPath]
  }
}

The end goal here is to create first a shallow copy into an existing object and possibly expand that out to include a deep copy based on the value type.





Aucun commentaire:

Enregistrer un commentaire