Skip to content

Instantly share code, notes, and snippets.

@calimarkus
Created February 8, 2013 16:53
Show Gist options
  • Save calimarkus/4740312 to your computer and use it in GitHub Desktop.
Save calimarkus/4740312 to your computer and use it in GitHub Desktop.
UIView+DTDebug.h (debug background calls on uiview methods)
#import "UIView+DTDebug.h"
#import "NSObject+DTRuntime.h"
@implementation UIView (DTDebug)
- (void)methodCalledNotFromMainQueue:(NSString *)methodName
{
NSLog(@"-[%@ %@] being called on background queue. Break on -[UIView methodCalledNotFromMainQueue:] to find out where", NSStringFromClass([self class]), methodName);
}
- (void)_setNeedsLayout_MainQueueCheck
{
if (dispatch_get_current_queue() != dispatch_get_main_queue())
{
[self methodCalledNotFromMainQueue:NSStringFromSelector(_cmd)];
}
// not really an endless loop, this calls the original
[self _setNeedsLayout_MainQueueCheck];
}
- (void)_setNeedsDisplay_MainQueueCheck
{
if (dispatch_get_current_queue() != dispatch_get_main_queue())
{
[self methodCalledNotFromMainQueue:NSStringFromSelector(_cmd)];
}
// not really an endless loop, this calls the original
[self _setNeedsDisplay_MainQueueCheck];
}
- (void)_setNeedsDisplayInRect_MainQueueCheck:(CGRect)rect
{
if (dispatch_get_current_queue() != dispatch_get_main_queue())
{
[self methodCalledNotFromMainQueue:NSStringFromSelector(_cmd)];
}
// not really an endless loop, this calls the original
[self _setNeedsDisplayInRect_MainQueueCheck:rect];
}
+ (void)toggleViewMainQueueChecking
{
[UIView swizzleMethod:@selector(setNeedsLayout)
withMethod:@selector(_setNeedsLayout_MainQueueCheck)];
[UIView swizzleMethod:@selector(setNeedsDisplay)
withMethod:@selector(_setNeedsDisplay_MainQueueCheck)];
[UIView swizzleMethod:@selector(setNeedsDisplayInRect:)
withMethod:@selector(_setNeedsDisplayInRect_MainQueueCheck:)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment