Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:01:39+00:00 2026-06-12T11:01:39+00:00

This is a bit of a tricky scenario. I’ve been studying blocks and started

  • 0

This is a bit of a tricky scenario. I’ve been studying blocks and started implementing them for the first time, and I found myself wanting to create a “compound block”. Here’s my code, roughly:

- (void)moveToPosition:(NSInteger)pos withVelocity:(CGFloat)vel onCompletion:(void(^)(BOOL completed))completionBlock
{

    void (^compoundBlock) (BOOL completed) = ^(BOOL completed) {
        [self unlockInteractionFromPullDownMenuTab];
        void(^innerCompletionBlock)(BOOL completed) = completionBlock;
        innerCompletionBlock(completed);
    };

    // Animate
    [UIView animateWithDuration: duration
                     animations: ^void{ [self.pullDownMenu setFrame:newFrame]; }
                     completion: compoundBlock
     ];


}

The goal is to take a block of code that is passed into this method, add something to it, and then pass it into an animation method call. However, I get a bad access on the line:

innerCompletionBlock(completed);

I figure that my innerCompletionBlock is getting deallocated, but I’m not entirely sure why. From what I understand, blocks copy everything that you throw at them, including references to self–which can create retain cycles, and which I recently learned to avoid.

Actually, I originally tried this:

void (^compoundBlock) (BOOL completed) = ^(BOOL completed) {
    [self unlockInteractionFromPullDownMenuTab];
    completionBlock(completed);
};

But I was getting the bad access, and I figured that perhaps the compoundBlock wasn’t copying the completionBlock, so I explicitly declared a (block) variable inside the block and assigned it to try to get it to retain (perhaps a bit silly, but I’m running under ARC so I can’t do manual retain calls).

Anyway, clearly the compoundBlock is being retained when it’s passed to UIView, but I’m unsure how to retain my onCompletion/innerCompletionBlock within the compoundBlock since I’m running under ARC.

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:01:40+00:00Added an answer on June 12, 2026 at 11:01 am

    Aha, figured it out. Bit stupid, really.

    There are various times where I was calling the method - (void)moveToPosition:... and passing nil to the completionBlock parameter…because I just didn’t need to do anything extra at the end of the animation and only wanted the [self unlockInteractionFromPullDownMenuTab]; that was tacked on in the compoundBlock.

    Makes sense, right?

    …Only if you check for nil before you call the block. As discussed elsewhere on SO, “When you execute a block, it’s important to test first if the block is nil”. Well, I learned my lesson there.

    This code works:

    // Compound completion block
    void (^compoundBlock) (BOOL completed) = ^(BOOL completed) {
        [self unlockInteractionFromPullDownMenuTab];
        if (completionBlock != nil) {
            completionBlock(completed);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this might be a bit tricky. First here is my function: public function transfer_smf_userinfo($username)
Bit tricky question but this saves lot of time if you have to modify
This is a deceptively tricky little bit of HTML/JS that has either me or
I'm finding this a bit tricky! Maybe someone can help me on this one
This one is bit tricky , I created jsfiddle here http://jsfiddle.net/WXmcL/10/ to kinda replicate
This is a bit tricky and I'd be glad if you guys could give
This might be a bit tricky setup but... I have this Silverlight project that
this is a little bit tricky. usually when someone clicks on a link that
This is a bit tricky and I couldn't come up with anything concise. I
This is a bit tricky to explain, but I will do my best. Say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.