I am new to blocks. I want to create a iVar NSMutableArray which I can access inside a block method.Can someone please tell me how to declare it using _block keyword?`
@interface ViewController : UIViewController
{
__block NSMutableArray *array;
}
@property (nonatomic, weak) NSMutableArray *array;
You don't need to set the __block in front of your iVar.
According to : http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/Blocks/Articles/bxVariables.html
When a block is copied, it creates strong references to object variables used within the block. If you use a block within the implementation of a method:
- If you access an instance variable by reference, a strong reference is made to self;
- If you access an instance variable by value, a strong reference is made to the variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With