在 ReactiveCocoa (RAC)
中 使用@weakify
和@strongify
来避免循环引用
请各位帮忙看下我这么写有没有错误?
testControler
中
@interface testControler ()
@property(nonatomic, strong) DynamicListViewModel *dynamicListViewModel;
@end
@implementation testControler
- (void)initData {
self.dynamicListViewModel = [[DynamicListViewModel alloc] init];
@weakify(self);
// 监听动态列表
[RACObserve(self.dynamicListViewModel, dataArray) subscribeNext:^(id x) {
// 这里用不用写 @strongify(self)?????
[self.tbl_dymicList reloadData];
}];
[self.dynamicListViewModel.loadCommand execute:nil];
[self.dynamicListViewModel.loadCommand.errors subscribeNext:^(NSError *x) {
@strongify(self);
[self showErrorMsg:x.domain];
}];
[[self.dynamicListViewModel.loadCommand.executing skip:1] subscribeNext:^(NSNumber *x) {
// 这里用不用写 @strongify(self)?????
if ([x boolValue]) {
[self showProgress];
} else {
[self hideProgress];
}
}];
[self.dynamicListViewModel.loadNextCommand.errors subscribeNext:^(NSError *x) {
@strongify(self);
[self showErrorMsg:x.domain];
}];
}
@end
请各位讲解下注释中的疑问,能画下内存图更感激
通过测试打印
dealloc
方法确认代码中的疑问部分都需要使用@strongify(self)
来打破循环引用