Re: Block gets NULL-ified when animation completes
Re: Block gets NULL-ified when animation completes
- Subject: Re: Block gets NULL-ified when animation completes
- From: Ken Thomases <email@hidden>
- Date: Thu, 15 Aug 2013 10:23:50 -0500
On Aug 15, 2013, at 9:49 AM, Jens Alfke wrote:
> On Aug 15, 2013, at 5:41 AM, Vlad Alekseev <email@hidden> wrote:
>
>> dispatch_block_t block = ^{
>> printf("finished");
>> };
>>
>> UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
>> [self.collectionView performBatchUpdates:^{
>> layout.minimumInteritemSpacing = 20;
>> } completion:^(BOOL finished) {
>> block();
>> }];
>
> As I said before, this is a bug in your code. ‘block’ needs to be copied since it is going to be called after the calling function returns.
>
> Yes, the collection view copies the completion block you pass it. But that block is not ‘block’, it’s the inline block literal that calls ‘block’. That gets copied, but when that is called it still tries to call the uncopied ‘block’, which fails.
When a block gets copied, it copies any blocks it has captured. So, the fact that the completion block is copied by the framework code is sufficient.
https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/Blocks/Articles/bxVariables.html#//apple_ref/doc/uid/TP40007502-CH6-SW7
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden