一、__block理解:Blocks可以访问局部变量,但是不能修改,声明block的时候实际上是把当时的临时变量又复制了一份,在block里即使修改了这些复制的变量,也不影响外面的原始变量。即所谓的闭包。 如果修改局部变量,需要加__block。 API Referenc ...
一、__block理解:
Blocks可以访问局部变量,但是不能修改,
声明block的时候实际上是把当时的临时变量又复制了一份,
在block里即使修改了这些复制的变量,也不影响外面的原始变量。即所谓的闭包。
如果修改局部变量,需要加__block。
API Reference对__block变量修饰符有如下几处解释
//A powerful feature of blocks is that they can modify variables in the same lexical scope. You signal that a block can modify a variable using the __block storage type modifier. //At function level are __block variables. These are mutable within the block (and the enclosing scope) and are preserved if any referencing block is copied to the heap.
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:__Block与__Weak区别
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。