Changing an instance variable in a block

I'm rather confused about how to change an instance variable inside a block.

Interface File (.h):

@interface TPFavoritesViewController : UIViewController { bool refreshing; } 

Implementation:

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

As you might have guessed, I get a save cycle warning when I try to change a refreshing ivar inside a block. How can I do this without errors?

+6
source share
1 answer

Your refreshing is an implicit reference to self , this is a shorthand for:

 self->refreshing = YES; 

hence a warning cycle. Change it to:

 temp_self->refreshing = YES; 
+6
source

Source: https://habr.com/ru/post/921815/


All Articles