0

I have the following initializer:

- (id) initWithBlock:(void(^)void) block;

and within the initializer I want to assign the block to a property so that it can be executed at a later time.

typedef void(^block)(void);
@interface myClass()
@property (X, nonatomic)    block theBlock;
@end

What should X be and why? (using ARC)

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • I have just taken a look to this [question](http://stackoverflow.com/questions/3935574/can-i-use-objective-c-blocks-as-properties). I'm not sure 100% but maybe `copy` is the best approach. – Jonathan Naguin Apr 25 '12 at 19:29
  • `copy` and `strong` are definitely *not* equivalent under ARC. – BJ Homer Apr 25 '12 at 19:30

2 Answers2

1

You need to copy a block.

If you want details, please see an article by Mike Ash on the topic. Even if you don't want the details you should read it.

http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87
0

You should use copy. A block which has not been copied lives on the stack. Retaining something on the stack would be meaningless.

Heiberg
  • 5,507
  • 2
  • 26
  • 28