Skip to content

Instantly share code, notes, and snippets.

@boucher
Created September 21, 2008 06:24
Show Gist options
  • Save boucher/11846 to your computer and use it in GitHub Desktop.
Save boucher/11846 to your computer and use it in GitHub Desktop.
- (void)_replaceSetters
{
var rootClass = [_targetObject class],
currentClass = rootClass;
while (currentClass && currentClass != currentClass.super_class)
{
var methodList = currentClass.method_list,
count = methodList.length;
for (var i=0; i<count; i++)
{
var methodName = methodList[i].name,
methodImplementation = methodList[i].method_imp,
setterKey = kvoKeyForSetter(methodName);
if (setterKey)
{
print("Replacing: "+methodName+" key: "+setterKey);
var newMethodImp = function(self)
{
[self willChangeValueForKey:setterKey];
methodImplementation.apply(self, arguments);
[self didChangeValueForKey:setterKey];
}
if (rootClass == currentClass)
method_setImplementation(methodList[i], newMethodImp);
else
class_addMethod(rootClass, methodName, newMethodImp, "");
}
}
currentClass = currentClass.super_class;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment