MVC – 变种
MVP
@interface MJAppPresenter() <MJAppViewDelegate>
@property (weak, nonatomic) UIViewController *controller;
@end
@implementation MJAppPresenter
- (instancetype)initWithController:(UIViewController *)controller
{
if (self = [super init]) {
//把UIViewController传到MJAppPresenter中
self.controller = controller;
// 创建View
MJAppView *appView = [[MJAppView alloc] init];
appView.frame = CGRectMake(100, 100, 100, 150);
appView.delegate = self;
[controller.view addSubview:appView];
// 加载模型数据
MJApp *app = [[MJApp alloc] init];
app.name = @"QQ";
app.image = @"QQ";
// 赋值数据
[appView setName:app.name andImage:app.image];
}
return self;
}
@end
MVVM
ViewModel与View之间形成一个双向绑定,ViewModel的里面属性的更新会及时通知到View上,可以用KVO、RAC、KVOController来实现。
//view中
// 设置数据
self.name = app.name;
self.image = app.image;
//ViewModel中
- (void)setViewModel:(MJAppViewModel *)viewModel
{
_viewModel = viewModel;
__weak typeof(self) waekSelf = self;
[self.KVOController observe:viewModel keyPath:@"name" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
waekSelf.nameLabel.text = change[NSKeyValueChangeNewKey];
}];
[self.KVOController observe:viewModel keyPath:@"image" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
waekSelf.iconView.image = [UIImage imageNamed:change[NSKeyValueChangeNewKey]];
}];
}
你自己用过哪些设计模式?
一般开始做一个项目,你的架构是如何思考的?
架构(Architecture)
软件开发中的设计方案
类与类之间的关系、模块与模块之间的关系、客户端与服务端的关系
经常听到的架构名词
MVC、MVP、MVVM、VIPER、CDD
三层架构、四层架构
……