Unmanaged
][1] structure. [1]: https://developer.apple.com/reference/swift/unmanaged
weak
-keyword should be used, if a referenced object may be deallocated during the lifetime of the object holding the reference.
unowned
-keyword should be used, if a referenced object is not expected to be deallocated during the lifetime of the object holding the reference.
Example:
class A : CLLocationManagerDelegate
{
init()
{
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.startLocationUpdates()
}
}
This example will not work properly, as the location manager is deallocated after the initializer returns. The proper solution is to create a strong reference as an instance variable:
class A : CLLocationManagerDelegate
{
let locationManager:CLLocationManager
init()
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.startLocationUpdates()
}
}