InterviewSolution
| 1. |
How should one consider the usage of strong, weak and unowned references? |
|
Answer» ASK yourself, "Am I dealing with REFERENCE types?" to see if you need to worry about strong, weak, or unowned. If you are working with Structs or Enums, ARC is not in charge of memory management, so you do not have to worry about defining weak or unowned constants or variables. In hierarchical relationships, strong references are acceptable when the parent REFERS to the child, but not when the child refers to the parent. Strong references are, in fact, the most appropriate type of reference the majority of the time. If two instances are optionally linked, make sure ONE of them has a weak reference to the other. When two instances are linked to the point where one cannot exist without the other, the instance with the OBLIGATORY dependency must keep an unowned reference to the other instance. |
|