美文网首页
swift 报错 Call to method 'confirm

swift 报错 Call to method 'confirm

作者: i爱吃土豆的猫 | 来源:发表于2021-07-01 14:52 被阅读0次

报错
Call to method 'confirmBtnAct' in closure requires explicit use of 'self' to make capture semantics explicit

在closure(闭包)内调用当前对象的属性或方法的时候,没有明确添加self指定
关于为什么要在closure内添加self关键字:
由于closure是异步加载的,所以在closure内的代码真正的被调用的时候需要保证对象仍然存在,由于iOS的ARC机制,这里添加的self实际上等于给对象的引用数+1,在closure结束的时候在释放掉。确保了内存的管理,避免了内存泄漏。

相关文章

网友评论

      本文标题:swift 报错 Call to method 'confirm

      本文链接:https://www.haomeiwen.com/subject/mrbjultx.html