Created
September 21, 2008 06:24
-
-
Save boucher/11846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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