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 7042629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:30+00:00 2026-05-28T02:11:30+00:00

I want a block that is available throughout a class, so it can be

  • 0

I want a block that is available throughout a class, so it can be re-used many times by different methods in the instance.

I want that block to be able to reference self.

I want to not have the block create any nasty retain cycles by retaining self.

So far I am stumped. I managed to create block in the .m outside of any method definitions, and that got me partway – I could reuse the block everywhere, but I couldn’t access self. I tried putting the block into an ivar but I’m doing something wrong there and now I’m getting random EXC_BAD_ACCESS. Can someone explain it simply, line by line?

  • 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-05-28T02:11:30+00:00Added an answer on May 28, 2026 at 2:11 am

    I figured it out.

    In MyClass.h:

    typedef void (^DefaultFailureBlock)();
    
    @property (copy) DefaultFailureBlock defaultFailureBlock;
    

    in the init method:

    __block MyClass *selfReq = self;
    self.defaultFailureBlock = ^{
        //use selfReq instead of self in here.
    };
    

    Interestingly, if you accidentally refer to self inside the block, you will have a retain cycle, and Analyze will not complain. I put an NSLog in dealloc to prove that it is actually being dealloced, and it is.

    Oh and don’t forget to [defaultFailureBlock release]; in dealloc too…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a stack of resources that will be used by different
I want to match a block of code multiple times in a file but
I have a large block of data in memory that I don't want Windows
I want to create an application that give users the options to block any
I want to write a method that does not block. The method doesn't return
The problem: we have critical path code that should never block. In many places
I've got a block of code that's doing what I want - it generates
I have blocks of content that are toggled on/off via jQuery and I want
I want to block non-browser clients from accessing certain pages / successfully making a
I have created a simple web browser using c# and I want to block

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.