Skip to content

Instantly share code, notes, and snippets.

@magicseth
Created April 13, 2011 21:10
Show Gist options
  • Save magicseth/918427 to your computer and use it in GitHub Desktop.
Save magicseth/918427 to your computer and use it in GitHub Desktop.
some code to help catch tricky background thread UI bugs
//
// 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
@newacct
Copy link

newacct commented Jul 2, 2012

[[NSThread currentThread] isMainThread]

can be written as

[NSThread isMainThread]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment