Search code examples
objective-ciosautomatic-ref-countingblock

Retaining/Copy Block Arc [iOS]


I have seen a lot of answers around, but I couldn't find any solution for my problem.

I basically have a Class where I only use class methods. I never allocate this class. So, I am passing a block to it and storing it on a static on the .h of the class, like this:

static ErrorBlock _errorBlock;

I am storing this way:

_errorBlock = [errorBlock copy];

I receive errorBlock as a parameter of a method. After some calculations, I invoke the block like this:

   _errorBlock(error);

It's worth saying that I am invoking this from a Class's Category. The application basically returns:

EXC_BAD_ACCESSS(code=2, adress = 0xc)

When I check the _errorBlock value, it's nil. So my question is, how can I keep a live reference to the block?


Solution

  • I was able to work it out, my removing completely the use of global blocks. At the moment I use the blocks my passing them as parameters.