setValue for Key to a class object in swift

402 views Asked by At

In objective-c we can use setValue:forKey method on any object, including class object. Is there a way to achieve the same in swift?

What I want to do here is I have NSManagedObject subclass and I have another model object for the same entity but non managed object. This way, within coredata stack, I can use the managed object and outside of it I can use normal modal.

Now my need is that when I have model object available and have the entity name, I want to populate all values from one object to another. For that, I am using object mirroring to get variable name and value from first object.

The challenge is how to set the value for the variable name (which I have in string) for the second object. Objective-C's setValue:forKey was very useful here.

0

There are 0 answers