Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use copy for block properties? [duplicate]

Why should bloc properties be declared as copy?

typedef void(^Thunk)(void);
@property (nonatomic, copy) Thunk block;

Why is it necessary to make a copy of the block object?

like image 546
cfischer Avatar asked Feb 19 '14 17:02

cfischer


People also ask

What's the difference between copy and duplicate?

Duplicate creates a copy of an item in the same location as the original. Copying (or “Copy To”) creates a copy of an item in a different location that you specify.

What is the difference between clone duplicate and copy in Corel Draw?

Clone just lets you select how many copies you want. Eg if you want to duplicate a field (or multiple fields) several times, then just select the field(s) and use clone. It will prompt for how many copies you want, then create that many in one go. Duplicate just does one duplicate of all selected fields at a time.

What is block copy?

Block Copy Definition The BlockCopy instruction is used to copy data or text from its Source registers to specified sequential Destination registers.


1 Answers

If you're going to use the block outside of the scope where it was defined, you need to make a copy of it, because that copies it to the heap. The original block is allocated on the stack, and so it will be deallocated when it goes out of scope, aka when the method or block of code that it was defined in finishes. Most often blocks are used for asynchronous activities, so often you need to do this.

like image 110
Gavin Avatar answered Sep 24 '22 02:09

Gavin