Skip to content

Instantly share code, notes, and snippets.

@danieleggert
Created December 4, 2014 18:07
Show Gist options
  • Select an option

  • Save danieleggert/c14d4c1856e2a3ff6ceb to your computer and use it in GitHub Desktop.

Select an option

Save danieleggert/c14d4c1856e2a3ff6ceb to your computer and use it in GitHub Desktop.

Revisions

  1. danieleggert created this gist Dec 4, 2014.
    31 changes: 31 additions & 0 deletions teardown.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    @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