2012-08-12 39 views
0

例如,WhereamiViewController擁有CLLocationManager, 和CLLocationManager的代表是 WhereamiViewController混亂上代表所有權

我在WhereamiViewController如何擁有當所有WhereamiViewController已經是一個實例變量指的是類CLLocationManager的對象CLLocationManager類混淆。有人能幫我清楚這個概念嗎?

#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 
+0

弱引用,我的朋友,弱引用。 – 2012-08-12 17:09:40

+0

WhereamiViewController不擁有CLLocationManager類,它擁有實例locationManager,因爲它使用alloc init創建它。 – rdelmar 2012-08-12 17:09:57

回答

0

CLLocationManager的代表根據docs不保留:

@屬性(分配,非原子)代表的id

因此,您的代理不被CLLocationManger保留,因此沒有保留循環。