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?
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.
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.
Block Copy Definition The BlockCopy instruction is used to copy data or text from its Source registers to specified sequential Destination registers.
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.
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