Skip to content

Instantly share code, notes, and snippets.

@danieleggert
Created December 4, 2014 18:07
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 danieleggert/c14d4c1856e2a3ff6ceb to your computer and use it in GitHub Desktop.
Save danieleggert/c14d4c1856e2a3ff6ceb to your computer and use it in GitHub Desktop.
Tear Down for async code
@implementation Foo
{
BOOL _needsTearDown;
}
- (instancetype)init;
{
self = [super init];
if (self) {
_needsTearDown = YES;
// initialization here
}
return self;
}
- (void)tearDown;
{
if (_needsTearDown) {
// tear down back pointers and async code here.
_needsTearDown = NO;
}
}
- (void)dealloc
{
if (_needsTearDown) {
__builtin_trap();
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment