You can just use class_replaceMethod
from the objc runtime to replace the implementation of the getter.
Example:
- (void)replaceGetters {
unsigned int numberOfProperties;
objc_property_t *propertyArray = class_copyPropertyList([self class], &numberOfProperties);
for (NSUInteger i = 0; i < numberOfProperties; i++) {
objc_property_t property = propertyArray[i];
const char *attrs = property_getAttributes(property);
NSString *name = [[NSString alloc] initWithUTF8String:property_getName(property)];
// property.getter = SEL; //?
// becomes
class_replaceMethod([self class], NSSelectorFromString(name), (IMP)myNewGetter, attrs);
}
}
id myNewGetter(id self, SEL _cmd) {
// do whatever you want with the variables....
// you can work out the name of the variable using - NSStringFromSelector(_cmd)
// or by looking at the attributes of the property with property_getAttributes(property);
// There's a V_varName in the property attributes
// and get it's value using - class_getInstanceVariable ()
// Ivar ivar = class_getInstanceVariable([SomeClass class], "_myVarName");
// return object_getIvar(self, ivar);
}