Skip to content

Instantly share code, notes, and snippets.

@objectiveSee
Last active August 29, 2015 14:06
Show Gist options
  • Save objectiveSee/6c62db7ba7d6e9c0b988 to your computer and use it in GitHub Desktop.
Save objectiveSee/6c62db7ba7d6e9c0b988 to your computer and use it in GitHub Desktop.
From Apple: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Blocks/Articles/bxUsing.html. You only need to make a copy when you expect the block to be used after destruction of the scope within which it was declared. Copying moves a block to the heap.
__weak EAFriendsListContacts *weakSelf = self;
phoneVerification.dismissBlock = ^(BOOL success, NSString *phoneNumber, NSString *verificationCode){
[button setEnabled:YES withSpinner:NO];
if (success) {
[[EAEffectManager sharedEffectManager] startEffect:EAEffectTypeConfettiApplause];
[weakSelf _refreshContactData];
}
};
@property (nonatomic, copy) void (^dismissBlock)(BOOL success, NSString *phoneNumber, NSString *verificationCode);
@objectiveSee
Copy link
Author

Follow up question: I have been using strong instead of copy in many many similar situations. Why has this never been a crash or issue?

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