Created
April 13, 2011 21:10
-
-
Save magicseth/918427 to your computer and use it in GitHub Desktop.
some code to help catch tricky background thread UI bugs
This file contains hidden or 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
// | |
// UIView+Threading.m | |
// | |
// Created by Seth Raphael on 4/12/11. | |
// Copyright 2011 BumpTechnologies. All rights reserved. | |
// | |
#ifdef DEBUG | |
@implementation UIView (UIView_Threading) | |
- (id) autorelease; | |
{ | |
if (![[NSThread currentThread] isMainThread]) { | |
[NSException raise:@"UIView Background Exception" format:@"Autoreleasing a UIView %@ on a background thread", self]; | |
} | |
return [super autorelease]; | |
} | |
- (void) release; | |
{ | |
if (![[NSThread currentThread] isMainThread]) { | |
[NSException raise:@"UIView Background Exception" format:@"Releasing a UIView %@ on a background thread", self]; | |
} | |
[super release]; | |
} | |
@end | |
@implementation UIViewController (UIViewController_Threading) | |
- (id) autorelease; | |
{ | |
if (![[NSThread currentThread] isMainThread]) { | |
[NSException raise:@"UIView Background Exception" format:@"Autoreleasing a UIView %@ on a background thread", self]; | |
} | |
return [super autorelease]; | |
} | |
- (void) release; | |
{ | |
if (![[NSThread currentThread] isMainThread]) { | |
[NSException raise:@"UIView Background Exception" format:@"Releasing a UIView %@ on a background thread", self]; | |
} | |
[super release]; | |
} | |
@end | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[[NSThread currentThread] isMainThread]
can be written as
[NSThread isMainThread]