錯誤寫法1
// ViewModel
@property (nonatomic, strong) UIViewController *controller;
// 在Viewcontroller中
@property (nonatomic, strong) VerityOtpViewModel *viewModel;
self.viewModel.controller = self;

錯誤1.png
正確寫法1
// ViewModel
@property (nonatomic, weak) UIViewController *controller;
// 在Viewcontroller中
@property (nonatomic, strong) VerityOtpViewModel *viewModel;
self.viewModel.controller = self;;

正確1.png
錯誤寫法2
[[_signInBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
[self.view endEditing:YES];
self.viewModel.signInType = SignInTypeDictPassword;
}];

錯誤2.png
正確寫法2
@weakify(self);
[[_signInBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
@strongify(self);
[self.view endEditing:YES];
self.viewModel.signInType = SignInTypeDictPassword;
}];

正確2.png
錯誤寫法3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DeviceManagerCell *cell = [DeviceManagerCell cellWithTableView:tableView];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.queryTrustDeviceModel = self.deviceLists[indexPath.section];
cell.deleteBlock = ^{
QueryTrustDeviceModel *subModel = self.deviceLists[indexPath.section];
[self deleteAlert:subModel.model andWithDeleteModel:subModel];
};
return cell;
}

錯誤3.png
正確寫法3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DeviceManagerCell *cell = [DeviceManagerCell cellWithTableView:tableView];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.queryTrustDeviceModel = self.deviceLists[indexPath.section];
@weakify(self);
cell.deleteBlock = ^{
@strongify(self);
QueryTrustDeviceModel *subModel = self.deviceLists[indexPath.section];
[self deleteAlert:subModel.model andWithDeleteModel:subModel];
};
return cell;
}

正確3.png
錯誤寫法4
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifer"];
@weakify(self);
cell.clickItemBlock = ^(CellModel * _Nonnull model) {
@strongify(self);
[self didSelectRowMehod:model tableView:tableView];
};
return cell;
}

錯誤4.png
正確寫法4
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifer"];
@weakify(self);
@weakify(tableView);
cell.clickItemBlock = ^(CellModel * _Nonnull model) {
@strongify(self);
@strongify(tableView);
[self didSelectRowMehod:model tableView:tableView];
};
return cell;
}

正確4.png
錯誤寫法5
MRPinAlertConfig *config = [[MRPinAlertConfig alloc] init];
MRPinAlert *alert = [[MRPinAlert alloc] initWithConfig:config];
self.pinAlert = alert;
[alert show];
alert.pinBlock = ^(NSString * _Nonnull pin) {
[self.pinAlert hide];
self.viewModel.pin = pin;
[self activateBiometryWithPin:pin];
};
alert.cancelBlock = ^{
kStrongSelf(self)
[self.tableView reloadData];
};
alert.forgotBlock = ^{
kStrongSelf(self)
[self.tableView reloadData];
};

錯誤5.png
正確寫法5
MRPinAlertConfig *config = [[MRPinAlertConfig alloc] init];
MRPinAlert *alert = [[MRPinAlert alloc] initWithConfig:config];
self.pinAlert = alert;
[alert show];
@weakify(self)
alert.pinBlock = ^(NSString * _Nonnull pin) {
@strongify(self);
[self.pinAlert hide];
self.viewModel.pin = pin;
[self activateBiometryWithPin:pin];
};
alert.cancelBlock = ^{
kStrongSelf(self)
[self.tableView reloadData];
};
alert.forgotBlock = ^{
kStrongSelf(self)
[self.tableView reloadData];
};

正確5.png
注意: 如果block未訪問self,不需要寫@weakify(self),kStrongSelf(self)否則會出現(xiàn)警告“Unused variable 'self'”