weak와 unowned

w0308h 2월 14일 AM 09:03 2 0
w0308h Profile Image Level 9
2 #TIL

weak vs. unowned

  • Strong
    • Default. The child class exists as long as the parent exists.
  • Weak
    • Child 클래스는 존재하지 않을 수도 있다. Parent가 메모리에서 해제되면 존재하지 않는다. (Child my or may not exist. Will not exist if parent is removed from memory.)
    • 옵셔널 가능
    • weak let 불가
    • When the reference can become nil at some point in its lifetime.
  • Unowned
    • Child 클래스는 반드시 존재한다. Parent가 메모리에서 해제되면 (Child definitely exists all the time but is removed when parent is removed.)
    • 옵셔널 불가. 반드시 값이 있어야 함. let, var 모두 가능
    • When you know that the reference will NEVER be nil once set.
댓글