Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare iVar using blocks in objective c

Tags:

iphone

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;
like image 430
iOS_Passion Avatar asked Mar 12 '26 18:03

iOS_Passion


1 Answers

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.
like image 178
Zaphod Avatar answered Mar 14 '26 10:03

Zaphod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!