Objective c 代表所有权的困惑

Objective c 代表所有权的困惑,objective-c,delegates,Objective C,Delegates,例如,wheremiviewcontroller拥有CLLocationManager, 而CLLocationManager的委托是 miviewcontroller 当所有wheremiviewcontroller都是引用类CLLocationManager对象的实例变量时,我对wheremiviewcontroller如何拥有CLLocationManager类感到困惑。有人能帮我弄清楚这个概念吗 #import <UIKit/UIKit.h> #import <Core

例如,
wheremiviewcontroller
拥有
CLLocationManager
, 而
CLLocationManager
的委托是
miviewcontroller

当所有
wheremiviewcontroller
都是引用类
CLLocationManager
对象的实例变量时,我对
wheremiviewcontroller
如何拥有
CLLocationManager
类感到困惑。有人能帮我弄清楚这个概念吗

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}
@end

CLLocationManager
的委托不会根据以下条件保留:

@属性(赋值,非原子)id委托


因此,您的委托没有被
CLLocationManager
保留,因此没有保留循环。

弱引用,我的朋友,弱引用。MiViewController不拥有CLLocationManager类,它拥有实例locationManager,因为它使用alloc init创建了它。
#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