Is there way to check a `unowned` (actually `unowned(safe)`) reference has been deinited?

孤街浪徒 提交于 2019-12-04 06:48:23

Suddenly I have found that my original base assumption that weak reference in Swift can be slow is wrong. As we can see from sources, Swift is actually using almost same implementation for weak and unowned references. So weak reference is almost as fast as unowned reference.

(But Objective-C is completely different story, it is using sidetable with tracking of all pointers to week references and deinit, deallocate, and zeroing as one step. And it can be slow.)

And because of this, my questions makes no sense. I have to use week reference and unwrap it as I proposed it in the last piece of code in my original question.

Update: Here is an awesome article by incredible Mike Ash that describes how weak and unowned references work under the hood in Swift.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!