Graphics Programs Reference
In-Depth Information
line of code where you set the delegate of the locationManager disappears. Further-
more, if you want to implement additional methods from the CLLocationManager-
Delegate protocol in WhereamiViewController , those methods will now be
auto-completed by Xcode .
Delegation, controllers, and memory management
From the perspective of the model-view-controller pattern, WhereamiViewControl-
ler is a controller object. It is typically the case that delegates are controller objects. In
addition, a controller object typically owns the objects that are delegating to it. For ex-
ample, WhereamiViewController owns the CLLocationManager , and the
CLLocationManager 's delegate is the WhereamiViewController .
Figure 4.8 Controllers own objects, objects delegate to controllers
From our discussion in Chapter 3 , recall that this reciprocal relationship would create a re-
tain cycle if both objects held strong references to each other. To avoid such a cycle, the
CLLocationManager 's delegate property is not a strong reference. But it is not a
weak reference, either. To maintain backwards-compatibility with non-ARC versions of
iOS, delegate properties are __unsafe_unretained .
Because delegate is unsafe unretained instead of weak, it is not automatically set to
nil when the object it points to is destroyed. You have to do that yourself in the delegate
object's dealloc method.
In WhereamiViewController.m , override dealloc .
- (void)dealloc
{
// Tell the location manager to stop sending us messages
Search WWH ::




Custom Search