Skip to content

Instantly share code, notes, and snippets.

@kolyuchiy
Created September 14, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolyuchiy/121800839b041e8c0f78ab64eb739968 to your computer and use it in GitHub Desktop.
Save kolyuchiy/121800839b041e8c0f78ab64eb739968 to your computer and use it in GitHub Desktop.
static void LayoutLoggingForClassSelector(Class cls, SEL selector) {
static NSMutableDictionary *counters = nil;
if (!counters) {
counters = [NSMutableDictionary dictionary];
}
SEL selector = NSSelectorFromString(selectorName);
[cls aspect_hookSelector:selector withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> info) {
TLLOG(NL(@"lob %s %p"), class_getName([[info instance] class]), (void *)[info instance]);
} error:nil];
[cls aspect_hookSelector:selector withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info) {
NSValue *key = [NSValue valueWithPointer:(void *)[info instance]];
NSNumber *counter = counters[key];
if (!counter) {
counter = @(0);
}
counter = @(counter.integerValue + 1);
counters[key] = counter;
TLLOG(NL(@"loa %s %p %@"), class_getName([[info instance] class]), (void *)[info instance], counter);
} error:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment