I have two classes with the same set of properties, declared using the @property directive in a protocol, they both implement. Now I was wondering if it is possible to automatically populate an instance of the first class with the values from an instance of the second class (and vice-versa).
I would like this approach to be robust, so that if I change the of properties declared in the protocol there will be no need to add extra code in the copying methods.
I have two classes with the same set of properties, declared using the @property
Share
Yes, given the exact context there could be various approaches to this problem.
One I can think of at the moment is to first get all the properties of source object then use
setValue:value forKey:keyto set the values on the target object.Code to retrieve all custom properties:
You may want to checkout the Key-Value Coding Programming Guide for more information.