Skip to content

Commit

Permalink
add mediator
Browse files Browse the repository at this point in the history
  • Loading branch information
lovemo committed Apr 15, 2016
1 parent a08fe4f commit 9ab0237
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 4 deletions.
4 changes: 2 additions & 2 deletions SUIMVVMKit.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|

s.name = 'SUIMVVMKit'
s.version = '0.4.7
s.version = '0.4.8
s.summary = 'SUIMVVMKit is a MVVM frameWork easy to develop iOS'
s.homepage = 'https://github.com/lovemo/MVVMFramework'
s.platform = :ios, '7.0'
s.license = 'MIT'
s.author = { 'lovemo' => 'lovemomoyulin@qq.com' }
s.source = { :git => 'https://github.com/lovemo/MVVMFramework.git',:tag => '0.4.7' }
s.source = { :git => 'https://github.com/lovemo/MVVMFramework.git',:tag => '0.4.8' }
s.requires_arc = true
s.public_header_files = 'SUIMVVMKit/**/*.h'
s.source_files = 'SUIMVVMKit/SUIMVVMKit.h'
Expand Down
15 changes: 15 additions & 0 deletions SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "SMKViewProtocol.h"
#import "SMKViewModelProtocol.h"
#import "SMKViewMangerProtocol.h"
#import "SMKAbstractMediator.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions SUIMVVMKit/SUIMVVMKit/NSObject+SMKProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// SMKAbstractMediator.h
// SUIMVVMDemo
//
// Created by yuantao on 16/4/15.
// Copyright © 2016年 lovemo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SMKViewModelProtocol.h"
#import "SMKViewMangerProtocol.h"

@interface SMKAbstractMediator : NSObject

/**
* viewModel
*/
@property (nonatomic, strong) NSObject<SMKViewModelProtocol> *viewModel;

/**
* viewManger
*/
@property (nonatomic, strong) NSObject<SMKViewMangerProtocol> *viewManger;

/**
* 初始化
*/
- (instancetype)initWithViewModel:(id<SMKViewModelProtocol>)viewModel viewManger:(id<SMKViewMangerProtocol>)viewManger;

+ (instancetype)mediatorWithViewModel:(id<SMKViewModelProtocol>)viewModel viewManger:(id<SMKViewMangerProtocol>)viewManger;

/**
* 将infos通知viewModel
*/
- (void)noticeViewModelWithInfos:(NSDictionary *)infos;

/**
* 将infos通知viewMnager
*/
- (void)noticeViewMangerWithInfos:(NSDictionary *)infos;

@end
34 changes: 34 additions & 0 deletions SUIMVVMKit/SUIMVVMKit/SMKAbstractMediator.m
Original file line number Diff line number Diff line change
@@ -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<SMKViewModelProtocol>)viewModel viewManger:(id<SMKViewMangerProtocol>)viewManger {
if (self = [super init]) {
self.viewModel = (NSObject<SMKViewModelProtocol> *)viewModel;
self.viewManger = (NSObject<SMKViewMangerProtocol> *)viewManger;
}
return self;
}

+ (instancetype)mediatorWithViewModel:(id<SMKViewModelProtocol>)viewModel viewManger:(id<SMKViewMangerProtocol>)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
5 changes: 4 additions & 1 deletion SUIMVVMKit/SUIMVVMKit/SMKViewMangerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <UIKit/UIKit.h>


typedef void (^ViewEventsBlock)( );

/**
Expand All @@ -17,11 +18,13 @@ typedef void (^ViewEventsBlock)( );
typedef void (^ViewModelInfosBlock)( );



@protocol SMKViewMangerProtocol <NSObject>

@optional


- (void)smk_notice;

/**
* 设置Controller的子视图的管理者为self
*
Expand Down
6 changes: 5 additions & 1 deletion SUIMVVMKit/SUIMVVMKit/SMKViewModelProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <Foundation/Foundation.h>


/**
* 请求成功block
*/
Expand All @@ -30,10 +31,13 @@ typedef void (^progressBlock)(NSProgress * progress);
typedef void (^ViewMangerInfosBlock)( );



@protocol SMKViewModelProtocol <NSObject>

@optional


- (void)smk_notice;

/**
* 返回指定viewModel的所引用的控制器
*/
Expand Down

0 comments on commit 9ab0237

Please sign in to comment.