Changing an instance variable in a block

I am quite confused about how to change an instance variable inside of a block.

The interface file (.h):

  • Objective-C Blocks, Recursion Fails
  • Completion Blocks ? Asynchronous processes embedded in synchronous workflow
  • Reason to use ivars vs properties in objective c
  • How to dismiss own view controller and present another view controller in a button tap?
  • How do I create a global UIManagedDocument instance per document-on-disk shared by my whole application using blocks?
  • Pass value to closure?
  • @interface TPFavoritesViewController : UIViewController {
        bool refreshing;

    The implementation:

    __weak TPFavoritesViewController *temp_self = self;
    refreshing = NO;
    [myTableView addPullToRefreshWithActionHandler:^{
        refreshing = YES;
        [temp_self refresh];

    As you might guess, I get a retain cycle warning when I try to change the refreshing ivar inside of the block. How would I do this without getting an error?

    Solutions Collect From Internet About “Changing an instance variable in a block”

    Your assignment to refreshing is an implicit reference to self, it is shorthand for:

    self->refreshing = YES;

    hence the cycle warning. Change it to:

    temp_self->refreshing = YES;