Swift. Is the (absolutely) sole specific advantage of unowned over weak, performance?

后端 未结 3 845

In Swift, we have normal default typing

  • the object simply cannot become nil.

we have weak typing

  • the object can become nil. if the ob
3条回答
  •  离开以前
    2021-01-12 10:44

    The bold sentences are not true.

    Weak is optional and can be set at any time.

    Unowned is non-optional but can be nil. If that happens and you call it your app crashs. It has to be set during initialization.

    Another difference is performance, as the author stated. Unowned does not do any checks and is slighty faster than weak.

    It better shows the relationship between classes.

    You can check out this SO question for further details: What is the difference between a weak reference and an unowned reference?

提交回复
热议问题