iOS weak strong

@property (weak , nonatomic) FSCalendar *calendar;

FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 44, 320, 300)];
calendar.dataSource = self;
calendar.delegate = self;
[self.view addSubview:calendar];
self.calendar = calendar;
[self preferredStatusBarStyle];
理解:view是指向临时创建calendar对象的强指针,而self.calendar是弱指针,当view不释放,也会指向calendar,当view释放,则self。calendar也不再持有该对象。
所以self.calendar=[[FSCalendar alloc] initWithFrame:CGRectMake(0, 44, 320, 300)];是错误的写法,因为该对象创建后立即被释放。

你可能感兴趣的:(iOS weak strong)