diff --git a/SUIMVVMDemo/.DS_Store b/SUIMVVMDemo/.DS_Store index 9aa41c9..c252b6d 100644 Binary files a/SUIMVVMDemo/.DS_Store and b/SUIMVVMDemo/.DS_Store differ diff --git a/SUIMVVMDemo/SUIMVVMDemo.xcodeproj/project.pbxproj b/SUIMVVMDemo/SUIMVVMDemo.xcodeproj/project.pbxproj index 0f793dd..cbe5121 100644 --- a/SUIMVVMDemo/SUIMVVMDemo.xcodeproj/project.pbxproj +++ b/SUIMVVMDemo/SUIMVVMDemo.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 34870A4B1CBA4B1200EDEF26 /* ThirdView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34870A391CBA4B1200EDEF26 /* ThirdView.xib */; }; 34870A4C1CBA4B1200EDEF26 /* ThirdViewManger.m in Sources */ = {isa = PBXBuildFile; fileRef = 34870A3C1CBA4B1200EDEF26 /* ThirdViewManger.m */; }; 34870A4D1CBA4B1200EDEF26 /* ThirdViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 34870A3F1CBA4B1200EDEF26 /* ThirdViewModel.m */; }; + 3491C7291CC07922008A9312 /* SMKAbstractMediator.m in Sources */ = {isa = PBXBuildFile; fileRef = 3491C7281CC07922008A9312 /* SMKAbstractMediator.m */; }; 34F688BC1CB7B09E00518803 /* NSObject+SMKProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F688A51CB7B09E00518803 /* NSObject+SMKProperties.m */; }; 34F688BD1CB7B09E00518803 /* NSObject+SMKRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F688A71CB7B09E00518803 /* NSObject+SMKRequest.m */; }; 34F688BE1CB7B09E00518803 /* SMKAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F688A91CB7B09E00518803 /* SMKAction.m */; }; @@ -67,6 +68,8 @@ 34870A3C1CBA4B1200EDEF26 /* ThirdViewManger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewManger.m; sourceTree = ""; }; 34870A3E1CBA4B1200EDEF26 /* ThirdViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewModel.h; sourceTree = ""; }; 34870A3F1CBA4B1200EDEF26 /* ThirdViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewModel.m; sourceTree = ""; }; + 3491C7271CC07922008A9312 /* SMKAbstractMediator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SMKAbstractMediator.h; sourceTree = ""; }; + 3491C7281CC07922008A9312 /* SMKAbstractMediator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SMKAbstractMediator.m; sourceTree = ""; }; 34F688A41CB7B09E00518803 /* NSObject+SMKProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+SMKProperties.h"; sourceTree = ""; }; 34F688A51CB7B09E00518803 /* NSObject+SMKProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+SMKProperties.m"; sourceTree = ""; }; 34F688A61CB7B09E00518803 /* NSObject+SMKRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+SMKRequest.h"; sourceTree = ""; }; @@ -283,6 +286,8 @@ 34F688B81CB7B09E00518803 /* UIView+SMKConfigure.m */, 34F688B91CB7B09E00518803 /* UIView+SMKEvents.h */, 34F688BA1CB7B09E00518803 /* UIView+SMKEvents.m */, + 3491C7271CC07922008A9312 /* SMKAbstractMediator.h */, + 3491C7281CC07922008A9312 /* SMKAbstractMediator.m */, ); path = SUIMVVMKit; sourceTree = ""; @@ -662,6 +667,7 @@ 34F688BF1CB7B09E00518803 /* SMKStore.m in Sources */, 34F72F861C8BF6A90033ED03 /* AppDelegate.m in Sources */, 34870A4C1CBA4B1200EDEF26 /* ThirdViewManger.m in Sources */, + 3491C7291CC07922008A9312 /* SMKAbstractMediator.m in Sources */, 34870A451CBA4B1200EDEF26 /* FirstTableViewModel.m in Sources */, 34870A431CBA4B1200EDEF26 /* FirstCell.m in Sources */, 34870A4A1CBA4B1200EDEF26 /* ThirdView.m in Sources */, diff --git a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/Controller/ThirdVC.m b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/Controller/ThirdVC.m index e561849..424fb71 100644 --- a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/Controller/ThirdVC.m +++ b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/Controller/ThirdVC.m @@ -13,6 +13,7 @@ #import "ThirdView.h" #import "UIView+SMKEvents.h" #import "UIView+SMKConfigure.h" +#import "SMKAbstractMediator.h" @interface ThirdVC () @@ -62,6 +63,21 @@ - (void)viewDidLoad { // viewManger ----> info <----- viewModel 之间通过block方式交互 self.thirdViewManger.viewMangerInfosBlock = [self.viewModel smk_viewModelWithViewMangerBlockOfInfos:@{@"info" : @"viewManger"}]; + + // 中介者传值 + SMKAbstractMediator *mediator = [SMKAbstractMediator mediatorWithViewModel:self.viewModel viewManger:self.thirdViewManger]; + + self.thirdViewManger.smk_mediator = mediator; + self.viewModel.smk_mediator = mediator; + + self.thirdViewManger.smk_viewMangerInfos = @{@"xxxxxx" : @"22222222"}; + [self.thirdViewManger smk_notice]; + NSLog(@"viewManger------>viewModel==%@", self.viewModel.smk_viewModelInfos); + + self.viewModel.smk_viewModelInfos = @{@"oooooo" : @"888888888"}; + [self.viewModel smk_notice]; + NSLog(@"viewModel=====>viewManger==%@", self.thirdViewManger.smk_viewMangerInfos); + } - (IBAction)clickBtnAction:(UIButton *)sender { diff --git a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/View/ThirdView.m b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/View/ThirdView.m index a7f98cf..b054d37 100644 --- a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/View/ThirdView.m +++ b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/View/ThirdView.m @@ -45,8 +45,8 @@ - (IBAction)jumpOtherVC:(UIButton *)sender { //} - (void)smk_configureViewWithViewModel:(id)viewModel { + [viewModel smk_viewModelWithModelBlcok:^(id model) { - ThirdModel *thirdModel = (ThirdModel *)model; self.testLabel.text = thirdModel.title; }]; diff --git a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewManger/ThirdViewManger.m b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewManger/ThirdViewManger.m index b723a0e..a2da431 100644 --- a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewManger/ThirdViewManger.m +++ b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewManger/ThirdViewManger.m @@ -10,6 +10,7 @@ #import "FirstVC.h" #import "UIView+SMKEvents.h" #import "UIView+SMKConfigure.h" +#import "SMKAbstractMediator.h" @interface ThirdViewManger () @@ -53,6 +54,11 @@ - (void)smk_viewModel:(id)viewModel withInfos:(NSDictionary *)infos { NSLog(@"%@",infos); } +#pragma mark 中介者传值 +- (void)smk_notice { + [self.smk_mediator noticeViewModelWithInfos:self.smk_viewMangerInfos]; +} + //// 得到模型数据 //- (void)smk_viewMangerWithModel:(NSDictionary *(^)( ))dictBlock { // if (dictBlock) { diff --git a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewModel/ThirdViewModel.m b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewModel/ThirdViewModel.m index c0ac2ce..20ad224 100644 --- a/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewModel/ThirdViewModel.m +++ b/SUIMVVMDemo/SUIMVVMDemo/Classes/Src/TwoExample/ViewModel/ThirdViewModel.m @@ -63,4 +63,10 @@ - (ViewMangerInfosBlock)smk_viewModelWithViewMangerBlockOfInfos:(NSDictionary *) }; } +#pragma mark 中介者传值 +- (void)smk_notice { + [self.smk_mediator noticeViewMangerWithInfos:self.smk_viewModelInfos]; +} + + @end diff --git a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.h b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.h index 90ff7bd..d2592fd 100755 --- a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.h +++ b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.h @@ -10,6 +10,7 @@ #import "SMKViewProtocol.h" #import "SMKViewModelProtocol.h" #import "SMKViewMangerProtocol.h" +#import "SMKAbstractMediator.h" NS_ASSUME_NONNULL_BEGIN @@ -61,6 +62,20 @@ typedef void (^ViewModelInfosBlock)( ); */ @property (nonatomic, copy) ViewModelInfosBlock viewModelInfosBlock; +/** + * mediator + */ +@property (nonatomic, strong) SMKAbstractMediator *smk_mediator; + +/** + * smk_viewMangerInfos + */ +@property (nonatomic, copy) NSDictionary *smk_viewMangerInfos; + +/** + * smk_viewModelInfos + */ +@property (nonatomic, copy) NSDictionary *smk_viewModelInfos; @end diff --git a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.m b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.m index 813ca33..d022f2a 100755 --- a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.m +++ b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.m @@ -51,6 +51,36 @@ - (void)setViewModelBlock:(ViewModelBlock)viewModelBlock { objc_setAssociatedObject(self, @selector(viewModelBlock), viewModelBlock, OBJC_ASSOCIATION_COPY); } +/** + * mediator + */ +- (void)setSmk_mediator:(SMKAbstractMediator *)smk_mediator { + objc_setAssociatedObject(self, @selector(smk_mediator), smk_mediator, OBJC_ASSOCIATION_RETAIN); +} +- (SMKAbstractMediator *)smk_mediator { + return objc_getAssociatedObject(self, @selector(smk_mediator)); +} + +/** + * smk_viewMangerInfos + */ +- (void)setSmk_viewMangerInfos:(NSDictionary *)smk_viewMangerInfos { + objc_setAssociatedObject(self, @selector(smk_viewMangerInfos), smk_viewMangerInfos, OBJC_ASSOCIATION_COPY); +} +- (NSDictionary *)smk_viewMangerInfos { + return objc_getAssociatedObject(self, @selector(smk_viewMangerInfos)); +} + +/** + * smk_viewModelInfos + */ +- (void)setSmk_viewModelInfos:(NSDictionary *)smk_viewModelInfos { + objc_setAssociatedObject(self, @selector(smk_viewModelInfos), smk_viewModelInfos, OBJC_ASSOCIATION_COPY); +} +- (NSDictionary *)smk_viewModelInfos { + return objc_getAssociatedObject(self, @selector(smk_viewModelInfos)); +} + - (nullable NSDictionary *)smk_allProperties { unsigned int count = 0; diff --git a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.h b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.h new file mode 100644 index 0000000..cca4895 --- /dev/null +++ b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.h @@ -0,0 +1,42 @@ +// +// SMKAbstractMediator.h +// SUIMVVMDemo +// +// Created by yuantao on 16/4/15. +// Copyright © 2016年 lovemo. All rights reserved. +// + +#import +#import "SMKViewModelProtocol.h" +#import "SMKViewMangerProtocol.h" + +@interface SMKAbstractMediator : NSObject + +/** + * viewModel + */ +@property (nonatomic, strong) NSObject *viewModel; + +/** + * viewManger + */ +@property (nonatomic, strong) NSObject *viewManger; + +/** + * 初始化 + */ +- (instancetype)initWithViewModel:(id)viewModel viewManger:(id)viewManger; + ++ (instancetype)mediatorWithViewModel:(id)viewModel viewManger:(id)viewManger; + +/** + * 将infos通知viewModel + */ +- (void)noticeViewModelWithInfos:(NSDictionary *)infos; + +/** + * 将infos通知viewMnager + */ +- (void)noticeViewMangerWithInfos:(NSDictionary *)infos; + +@end diff --git a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.m b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.m new file mode 100644 index 0000000..b268a26 --- /dev/null +++ b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.m @@ -0,0 +1,34 @@ +// +// SMKAbstractMediator.m +// SUIMVVMDemo +// +// Created by yuantao on 16/4/15. +// Copyright © 2016年 lovemo. All rights reserved. +// + +#import "SMKAbstractMediator.h" +#import "NSObject+SMKRequest.h" + +@implementation SMKAbstractMediator + +- (instancetype)initWithViewModel:(id)viewModel viewManger:(id)viewManger { + if (self = [super init]) { + self.viewModel = (NSObject *)viewModel; + self.viewManger = (NSObject *)viewManger; + } + return self; +} + ++ (instancetype)mediatorWithViewModel:(id)viewModel viewManger:(id)viewManger { + return [[self alloc]initWithViewModel:viewModel viewManger:viewManger]; +} + +- (void)noticeViewModelWithInfos:(NSDictionary *)infos { + self.viewModel.smk_viewModelInfos = infos; +} + +- (void)noticeViewMangerWithInfos:(NSDictionary *)infos { + self.viewManger.smk_viewMangerInfos = infos; +} + +@end diff --git a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewMangerProtocol.h b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewMangerProtocol.h index 706e669..e911aae 100644 --- a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewMangerProtocol.h +++ b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewMangerProtocol.h @@ -9,6 +9,7 @@ #import + typedef void (^ViewEventsBlock)( ); /** @@ -17,11 +18,13 @@ typedef void (^ViewEventsBlock)( ); typedef void (^ViewModelInfosBlock)( ); - @protocol SMKViewMangerProtocol @optional + +- (void)smk_notice; + /** * 设置Controller的子视图的管理者为self * diff --git a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewModelProtocol.h b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewModelProtocol.h index 3036040..8566f84 100644 --- a/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewModelProtocol.h +++ b/SUIMVVMDemo/SUIMVVMDemo/SUIMVVMKit/SUIMVVMKit/SMKViewModelProtocol.h @@ -8,6 +8,7 @@ #import + /** * 请求成功block */ @@ -30,10 +31,13 @@ typedef void (^progressBlock)(NSProgress * progress); typedef void (^ViewMangerInfosBlock)( ); - @protocol SMKViewModelProtocol @optional + + +- (void)smk_notice; + /** * 返回指定viewModel的所引用的控制器 */