Skip to content

Instantly share code, notes, and snippets.

@robbywalker
Last active December 11, 2015 05:28
Show Gist options
  • Save robbywalker/4551874 to your computer and use it in GitHub Desktop.
Save robbywalker/4551874 to your computer and use it in GitHub Desktop.
+ (id)instrumentInstanceMessagesSwizzledAllocWithZone:(NSZone *)zone {
id result = [self instrumentInstanceMessagesSwizzledAllocWithZone:zone];
liveObjectClass[result] = self;
object_setClass(result, classes[self]);
return result;
}
+ (id)instrumentInstanceMessagesAddedAllocWithZone:(NSZone *)zone {
Method method = GetSuperMethod(self, @selector(allocWithZone:));
IMP imp = method_getImplementation(method);
id result = imp(self, @selector(allocWithZone:), zone);
runCallbacks(afterBlocks, result, self, @selector(allocWithZone:));
liveObjectClass[result] = self;
object_setClass(result, classes[self]);
return result;
}
// Later...
if (HasOwnClassMethod(cls, @selector(allocWithZone:))) {
ClassMethodSwizzle(
cls, @selector(instrumentInstanceMessagesSwizzledAllocWithZone:),
@selector(allocWithZone:));
} else {
ClassMethodCopy(cls, @selector(instrumentInstanceMessagesAddedAllocWithZone:),
@selector(allocWithZone:));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment