代码复用
oc 里面无法方法嵌套,可以用block实现代码复用。
/// 显示皮肤列表弹窗
- (void)showReaderThemeListView
{
[self hiddenReaderToolView];
void (^ showThemeAlertBlock)(void) = ^(void) {
self.toolTapGR.enabled = NO;
MJWeakSelf
HYMoreImageThemeAlertView *alertView = [HYMoreImageThemeAlertView showInView:self.view withThemeList:self.themeListArray closeBlock:^{
weakSelf.toolTapGR.enabled = YES;
}];
alertView.themeChangeBlock = ^{
[weakSelf moreThemeVCThemeChanged];
};
};
if (self.themeListArray && self.themeListArray.count > 0) {
showThemeAlertBlock();
} else {
MJWeakSelf
[self getThemeList:^(NSArray<HYImageThemeModel *> *_Nonnull array) {
if (array && array.count > 0) {
showThemeAlertBlock();
} else {
[HYToastView showRemindMessageToView:weakSelf.view withMessage:@"加载皮肤失败,请重试!"];
}
}];
}
}
在swift中 方法里面可以嵌套另一个方法。
网友评论