快速关闭中的自我反省在一段时间内返回零 [英] self refrence inside swift closure return nil some time

查看:17
本文介绍了快速关闭中的自我反省在一段时间内返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在快速访问闭包内的实例方法,在某些情况下,self 引用变为 nil,这会导致我的程序崩溃.我尝试使用 [weak self] 访问,但是当 selfnil 时,它无法调用实例方法.

I am accessing instance method inside closure in swift, self reference become nil in some cases which result crash my program. I tried to access using [weak self] but it failed to call the instance method when self is nil.

[weak self] () -> () in

推荐答案

我能够通过在创建强实例时创建强实例来解决这个问题,在我的例子中,这个弱变量使自身为零.感谢大家为我的疑问提供建议.

I am able to fix this issue by making strong instance while creating it, in my case this weak variable was making nil to self. Thanks all for providing suggestion for my queries.

这篇关于快速关闭中的自我反省在一段时间内返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆