So I have this problem in Objective-C. Let me set the stage of the problem.
I have a constraint, that doesn't allow me to modify the properties of an object. As it will assert that I am modifying that object without putting it between a write and commit transaction
ObjectA* constrainedObject = ...; // Retrieved from source with constraint applied.
constrainedObject.name = @"John"; // Assert tripped
[db writeTransaction];
constrainedObject.name = @"John"; // Does not assert
[db commitTransaction];
However if I create a new object, I can work around this limitation and modify the object by assigning the references to the unconstrainedObject
.
ObjectA* constrainedObject = ...; // Retrieved from source with constraint applied.
ObjectA* unconstrainedObject = [[ObjectA alloc] init];
unconstrainedObject.id = contrainedObject.id;
// Change name here
unconstrainedObject.name = @"John";
unconstrainedObject.home = @"Mansion";
unconstrainedObject.age = constrainedObject.age; // Keep old property
// This illustrates the problem.
// I still want to keep some of the properties of the old
// object but have to manually type it in.
So my question is how do retrieve all the property references from the constrainedObject
without manually typing that all out?
Is there a way to inspect and map the key value properties of an NSObject
over to another NSObject
of the same type ?