The API reference has the following explanations for the __block variable modifier:
A powerful feature ofBlocks is that they can modify variablesinch theSame lexical scope. You signal thataBlock can modifya variable using the__block storage type modifier.//at function level is __block variables. These is mutable within theBlock ( and theEnclosing scope) andis preservedif anyReferencing block is copied to theHeap.
The approximate meaning comes down to two points:
The 1.__block object can be modified and re-assigned in the block.
2.__block objects are not strongly referenced by block in block, so there is no circular reference problem.
The API reference has the following explanations for the __weak variable modifier:
a referencethatdoesnotthereferenceissettotothe object.
An object that uses the __weak modifier is equivalent to the property defined as weak. Nature does not cause circular reference problems, because the Apple documentation has made it clear that when the original object does not have any strong references, the weak reference pointer is also set to nil.
Therefore, the difference between the __block and __weak modifiers is actually quite obvious:
1.__block can be used in either ARC or MRC mode, can be decorated with objects, and can also be decorated with basic data types.
2.__weak can only be used in Arc mode, can only be decorated with objects (nsstring), and cannot be decorated with basic data types (int).
The 3.__block object can be re-assigned in the block, __weak not.
The ps:__unsafe_unretained modifier can be considered an alternative to iOS SDK version __weak, but will not be automatically empty to nil. So do not use this modifier as much as possible.
What is the difference between __weak and __block modifiers?