For example,
WhereamiViewControllerowns theCLLocationManager,
and theCLLocationManager‘s delegate is the
WhereamiViewController.
I’m confused on how the WhereamiViewController owns the CLLocationManager class when all WhereamiViewController has is an instance variable referring to an object of the class CLLocationManager. Could somebody help clear this concept to me?
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@end
#import "WhereamiViewController.h"
@implementation WhereamiViewController
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate: self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
}
return self;
}
@end
CLLocationManager‘s delegate is not retained according to the docs:So, your delegate is not retained by the
CLLocationManger, thus there is no retain loop.