What is the difference in Swift between 'unowned(safe)' and 'unowned(unsafe)'?

前端 未结 4 1621
醉话见心
醉话见心 2020-12-24 06:51

Apple\'s Swift Programming Language Guide mentions the capture specifiers unowned(safe) and unowned(unsafe), in addition to weak

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 07:06

    A simple Definition. which would clear the confusion.

    -- unowned attributes : If you try to access an unowned reference after the instance that it refers to is deallocated, your program will crash.

    -- unowned(Unsafe) attributes: If you try to access an unsafe unowned reference after the instance that it refers to is deallocated, your program will try to access the memory location where the instance used to be, which is an unsafe operation. (no guarantee wether this would executes or crashes)

提交回复
热议问题