0

suppose I do this:

MyClass *vista = [[MyClass alloc] initWithFrame:CGRectZero];

vista.onFinish = ^{
    CGRect rect = vista.bounds;
    // bla bla bla
};

then xcode will award me with this error: capturing vista strongly in this block is likely to lead to a retain cycle

Someone suggested declaring vista like this

__unsafe_unretained MyClass *vista = [[MyClass alloc] initWithFrame:CGRectZero];

but the problem is this. vista variable is assigned to a property a few lines down.

self.myVista = vista;

and this is a nonatomic, strong property.

How do I solve that? I can declare a temporary id var to use that, but this appears to be a lame solution.

Any thought?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Duck
  • 34,902
  • 47
  • 248
  • 470

1 Answers1

2

Try this:

MyClass *vista = [[MyClass alloc] initWithFrame:CGRectZero];

__weak MyClass *weakVista = vista;    
vista.onFinish = ^{
    CGRect rect = weakVista.bounds;
    // bla bla bla
};
rmaddy
  • 314,917
  • 42
  • 532
  • 579