I have a block attached to a button (using this category):
__unsafe_unretained typeof(UIImage) *weakPic = originalPic;
[button addEventHandler:^{
switch (state) {
case state1:
{
UIViewController *vc = //some VC
vc.pic = weakPic; // weakPic is nil at this point
// putting originalPic here would solve my problem
// but then I would have a retain cycle
}
case state2:
{
// other stuff
}
}
}];
the action associated with the button is different depending on the state.
Here is the problem: I must keep the above __unsafe_unretained
to avoid having a retain cycle. However, this code is called at a point where originalPic = nil
.. and so when I assign weakPic
to vc.pic
I'm assigning it a nil value. If I replace weakPic
with just originalPic
, then it works fine.. (originalPic
will have the updated value) but then I get the retain cycle.. ideas?