text
stringlengths
9
39.2M
dir
stringlengths
26
295
lang
stringclasses
185 values
created_date
timestamp[us]
updated_date
timestamp[us]
repo_name
stringlengths
1
97
repo_full_name
stringlengths
7
106
star
int64
1k
183k
len_tokens
int64
1
13.8M
```objective-c // // YFViperView.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> @protocol YFViperView <NSObject> - (nullable UIViewController *)routeSource; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
60
```objective-c // // NSObject+YFViperAssembly.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "NSObject+YFViperAssembly.h" #import "YFViperViewPrivate.h" #import "YFViperPresenterPrivate.h" #import "YFViperInteractorPrivate.h" #import "YFViperWireframePrivate.h" #import "YFViperRouter.h" @implementation NSObject (YFViperAssembly) + (void)assembleViperForView:(id<YFViperViewPrivate>)view presenter:(id<YFViperPresenterPrivate>)presenter interactor:(id<YFViperInteractorPrivate>)interactor wireframe:(id<YFViperWireframePrivate>)wireframe router:(id<YFViperRouter>)router { //* // NSParameterAssert([view conformsToProtocol:@protocol(YFViperViewPrivate)]); // NSParameterAssert([presenter conformsToProtocol:@protocol(YFViperPresenterPrivate)]); // NSParameterAssert([interactor conformsToProtocol:@protocol(YFViperInteractorPrivate)]); // NSParameterAssert([wireframe conformsToProtocol:@protocol(YFViperWireframePrivate)]); // NSCParameterAssert([router conformsToProtocol:@protocol(YFViperRouter)]); // // [interactor conformsToProtocol:@protocol(YFViperInteractorPrivate)]; // NSAssert3(interactor.eventHandler == nil, @"Interactor (%@)'s eventHandler (%@) already exists when assemble viper for new eventHandler", interactor, interactor.eventHandler,presenter); // NSAssert3(interactor.dataSource == nil, @"Interactor (%@)'s dataSource (%@) already exists when assemble viper for new dataSource", interactor, interactor.dataSource,presenter); [interactor setEventHandler:presenter]; [interactor setDataSource:presenter]; // NSAssert3(wireframe.view == nil, @"Wireframe (%@)'s view (%@) already exists when assemble viper for new view", wireframe, wireframe.view,view); [wireframe setView:view]; [wireframe setRouter:router]; // NSAssert3(presenter.interactor == nil, @"Presenter (%@)'s interactor (%@) already exists when assemble viper for new interactor", presenter, presenter.interactor,interactor); // NSAssert3(presenter.view == nil, @"Presenter (%@)'s view (%@) already exists when assemble viper for new view", presenter, presenter.view,view); // NSAssert3(presenter.wireframe == nil, @"Presenter (%@)'s wireframe (%@) already exists when assemble viper for new router", presenter, presenter.wireframe,self); [presenter setInteractor:interactor]; [presenter setView:view]; [presenter setWireframe:wireframe]; if ([view respondsToSelector:@selector(viewDataSource)] && [view respondsToSelector:@selector(setViewDataSource:)]) { NSAssert3(view.viewDataSource == nil, @"View (%@)'s viewDataSource (%@) already exists when assemble viper for new viewDataSource", view, view.viewDataSource,presenter); view.viewDataSource = presenter; } NSAssert3(view.eventHandler == nil, @"View (%@)'s eventHandler (%@) already exists when assemble viper for new eventHandler", view, view.eventHandler,presenter); [view setEventHandler:presenter]; // */ } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/NSObject+YFViperAssembly.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
756
```objective-c // // YFRouter+YFEditor.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFRouter+YFEditor.h" #import "YFEditorBuilder.h" @implementation YFRouter (YFEditor) + (UIViewController *)viewForCreatingNoteWithDelegate:(id<YFEditorDelegate>)delegate { return [YFEditorBuilder viewForCreatingNoteWithDelegate:delegate router:[self new]]; } + (UIViewController *)viewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<YFEditorDelegate>)delegate { return [YFEditorBuilder viewForEditingNoteWithUUID:uuid title:title content:content delegate:delegate router:[self new]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Router/YFRouter+YFEditor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
172
```objective-c // // YFViperViewEventHandler.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> @protocol YFViperViewEventHandler @optional - (void)handleViewReady; - (void)handleViewRemoved; - (void)handleViewWillAppear:(BOOL)animated; - (void)handleViewDidAppear:(BOOL)animated; - (void)handleViewWillDisappear:(BOOL)animated; - (void)handleViewDidDisappear:(BOOL)animated; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperViewEventHandler.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
116
```objective-c // // YFViperRouter.h // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> @protocol YFViperRouter // YFRouter.h + (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source animated:(BOOL)animated; + (void)popViewController:(UIViewController *)viewController animated:(BOOL)animated; + (void)presentViewController:(UIViewController *)viewControllerToPresent fromViewController:(UIViewController *)source animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; + (void)dismissViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperRouter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
150
```objective-c // // YFViperPresenterPrivate.m // BigShow1949 // // Created by big show on 2018/10/17. // #import "YFViperPresenter.h" #import <Foundation/Foundation.h> @protocol YFViperWireframe,YFViperView,YFViperInteractor; // @protocol YFViperPresenterPrivate <YFViperViewPrivate> - (id<YFViperWireframe>)wireframe; - (void)setWireframe:(id<YFViperWireframe>)wireframe; - (void)setView:(id<YFViperView>)view; - (id<YFViperInteractor>)interactor; - (void)setInteractor:(id<YFViperInteractor>)interactor; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperPresenterPrivate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
171
```objective-c // // YFViperWireframe.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> @protocol YFViperView; @protocol YFViperWireframe<NSObject> @property (nonatomic, readonly,weak) id<YFViperView> view; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperWireframe.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
79
```objective-c // // YFViperInteractor.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> @protocol YFViperInteractor<NSObject> @property (nonatomic, readonly, weak) id dataSource; @property (nonatomic, readonly, weak) id eventHandler; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
77
```objective-c // // NSObject+YFViperAssembly.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> @protocol YFViperViewPrivate,YFViperPresenterPrivate,YFViperInteractorPrivate,YFViperWireframePrivate,YFViperRouter; @interface NSObject (YFViperAssembly) + (void)assembleViperForView:(id<YFViperViewPrivate>)view presenter:(id<YFViperPresenterPrivate>)presenter interactor:(id<YFViperInteractorPrivate>)interactor wireframe:(id<YFViperWireframePrivate>)wireframe router:(id<YFViperRouter>)router; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/NSObject+YFViperAssembly.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
170
```objective-c // // YFViperPresenter.m // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> @protocol YFViperPresenter @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // YFViperViewPrivate.m // BigShow1949 // // Created by big show on 2018/10/17. // #import "YFViperView.h" #import <Foundation/Foundation.h> @protocol YFViperViewEventHandler; @protocol YFViperViewPrivate <YFViperView> - (id<YFViperViewEventHandler>)eventHandler; - (void)setEventHandler:(id<YFViperViewEventHandler>)eventHandler; @optional - (id)viewDataSource; - (void)setViewDataSource:(id)viewDataSource; - (void)setRouteSource:(UIViewController *)routeSource; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperViewPrivate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
139
```objective-c // // YFViperWireframePrivate.h // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> #import "YFViperWireframe.h" #import "YFViperRouter.h" #import "YFViperView.h" @protocol YFViperWireframePrivate<YFViperWireframe> - (void)setView:(id<YFViperView>)view; - (id<YFViperRouter>)router; - (void)setRouter:(id<YFViperRouter>)router; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/Protocol/YFViperWireframePrivate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
133
```objective-c // // YFLoginInteractor.m // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFLoginInteractor.h" @implementation YFLoginInteractor @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Interactor/YFLoginInteractor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
53
```objective-c // // YFLoginInteractor.h // BigShow1949 // // Created by big show on 2018/12/11. // #import <Foundation/Foundation.h> @interface YFLoginInteractor : NSObject @property (nonatomic, weak) id dataSource; @property (nonatomic, weak) id eventHandler; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Interactor/YFLoginInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
71
```objective-c // // YFLoginViewDelegate.h // BigShow1949 // // Created by big show on 2018/12/11. // #ifndef YFLoginViewDelegate_h #define YFLoginViewDelegate_h @protocol YFLoginViewDelegate <NSObject> @optional - (void)loginViewController:(UIViewController *)loginViewController didLoginWithAccount:(NSString *)account; @end #endif /* YFLoginViewDelegate_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/View/YFLoginViewDelegate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
94
```objective-c // // YFLoginViewProtocol.h // BigShow1949 // // Created by big show on 2018/12/11. // #ifndef YFLoginViewProtocol_h #define YFLoginViewProtocol_h @protocol YFLoginViewProtocol @end #endif /* YFLoginViewProtocol_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/View/YFLoginViewProtocol.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
69
```objective-c // // YFLoginViewController.h // BigShow1949 // // Created by big show on 2018/12/11. // #import <UIKit/UIKit.h> #import "YFLoginViewDelegate.h" #import "YFViperView.h" #import "YFLoginViewProtocol.h" @interface YFLoginViewController : UIViewController<YFViperView, YFLoginViewProtocol> @property (nonatomic, weak) id<YFLoginViewDelegate> delegate; @property (nonatomic, copy, nullable) NSString *message; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/View/YFLoginViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
117
```objective-c // // YFLoginViewController.m // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFLoginViewController.h" @interface YFLoginViewController () @end @implementation YFLoginViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/View/YFLoginViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
166
```objective-c // // YFLoginViewEventHandler.h // BigShow1949 // // Created by big show on 2018/12/11. // #ifndef YFLoginViewEventHandler_h #define YFLoginViewEventHandler_h #endif /* YFLoginViewEventHandler_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/View/YFLoginViewEventHandler.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
60
```objective-c // // YFLoginViewPresenter.m // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFLoginViewPresenter.h" @implementation YFLoginViewPresenter @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Presenter/YFLoginViewPresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
53
```objective-c // // YFLoginViewPresenter.h // BigShow1949 // // Created by big show on 2018/12/11. // #import <Foundation/Foundation.h> @interface YFLoginViewPresenter : NSObject @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Presenter/YFLoginViewPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // YFLoginViewWireframe.m // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFLoginViewWireframe.h" @implementation YFLoginViewWireframe @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Wireframe/YFLoginViewWireframe.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
56
```objective-c // // YFLoginViewWireframe.h // BigShow1949 // // Created by big show on 2018/12/11. // #import <Foundation/Foundation.h> #import "YFViperWireframe.h" @interface YFLoginViewWireframe : NSObject<YFViperWireframe> @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Wireframe/YFLoginViewWireframe.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
71
```objective-c // // YFLoginBuilder.m // BigShow1949 // // Created by big show on 2018/12/11. // #import "YFLoginBuilder.h" #import "YFLoginViewController.h" #import "YFLoginViewPresenter.h" #import "YFLoginInteractor.h" #import "YFLoginViewWireframe.h" #import "NSObject+YFViperAssembly.h" @implementation YFLoginBuilder + (UIViewController *)viewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate router:(id<YFViperRouter>)router { YFLoginViewController *view = [[YFLoginViewController alloc] init]; view.delegate = delegate; view.message = message; [self buildView:(id<YFViperViewPrivate>)view router:router]; return view; } + (void)buildView:(id<YFViperViewPrivate>)view router:(id<YFViperRouter>)router { YFLoginViewPresenter *presenter = [[YFLoginViewPresenter alloc] init]; YFLoginInteractor *interactor = [[YFLoginInteractor alloc] init]; id<YFViperWireframePrivate> wireframe = (id)[[YFLoginViewWireframe alloc] init]; [self assembleViperForView:view presenter:(id<YFViperPresenterPrivate>)presenter interactor:(id<YFViperInteractorPrivate>)interactor wireframe:(id<YFViperWireframePrivate>)wireframe router:(id<YFViperRouter>)router]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Builder/YFLoginBuilder.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
357
```objective-c // // YFLoginBuilder.h // BigShow1949 // // Created by big show on 2018/12/11. // #import <Foundation/Foundation.h> @protocol YFLoginViewDelegate,YFViperRouter; @interface YFLoginBuilder : NSObject + (UIViewController *)viewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate router:(id<YFViperRouter>)router; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/LoginModule/Builder/YFLoginBuilder.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
96
```objective-c // // YFNoteListInteractor.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <Foundation/Foundation.h> #import "YFViperInteractor.h" #import "YFNoteListInteractorInput.h" @protocol YFNoteListDataService; @interface YFNoteListInteractor : NSObject<YFViperInteractor,YFNoteListInteractorInput> @property (nonatomic, weak) id dataSource; @property (nonatomic, weak) id eventHandler; - (instancetype)initWithNoteListDataService:(id<YFNoteListDataService>)service; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Interactor/YFNoteListInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
133
```objective-c // // YFNoteListInteractorInput.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> @class YFNoteModel; @protocol YFNoteListInteractorInput - (void)loadAllNotes; - (NSInteger)noteCount; - (NSString *)titleForNoteAtIndex:(NSUInteger)idx; - (NSString *)contentForNoteAtIndex:(NSUInteger)idx; - (YFNoteModel *)noteAtIndex:(NSUInteger)idx; - (NSString *)noteUUIDAtIndex:(NSUInteger)idx; - (NSString *)noteTitleAtIndex:(NSUInteger)idx; - (NSString *)noteContentAtIndex:(NSUInteger)idx; - (void)deleteNoteAtIndex:(NSUInteger)idx; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Interactor/YFNoteListInteractorInput.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
163
```objective-c // // YFNoteListDataService.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFNoteListDataService_h #define YFNoteListDataService_h @class YFNoteModel; @protocol YFNoteListDataService @property (nonatomic, readonly, strong) NSArray<YFNoteModel *> *noteList; - (void)fetchAllNotesWithCompletion:(void(^)(NSArray *notes))completion; - (void)storeNote:(YFNoteModel *)note; - (void)deleteNote:(YFNoteModel *)noteToDelete; @end #endif /* YFNoteListDataService_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Interactor/YFNoteListDataService.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
140
```objective-c // // YFNoteListViewProtocol.h // BigShow1949 // // Created by big show on 2018/10/18. // #ifndef YFNoteListViewProtocol_h #define YFNoteListViewProtocol_h #import <Foundation/Foundation.h> //#define _ZIKTNoteListViewProtocol_ (Protocol<ZIKTRoutableViewDynamicGetter> *)@protocol(ZIKTNoteListViewProtocol) @protocol YFNoteListViewProtocol <NSObject> - (UITableView *)tableView; - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath text:(NSString *)text detailText:(NSString *)detailText; @end #endif /* YFNoteListViewProtocol_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/View/YFNoteListViewProtocol.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
142
```objective-c // // YFNoteListInteractor.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFNoteListInteractor.h" #import "YFNoteModel.h" #import "YFNoteListDataService.h" @interface YFNoteListInteractor () @property (nonatomic, strong) id<YFNoteListDataService> noteListDataService; @end @implementation YFNoteListInteractor - (instancetype)initWithNoteListDataService:(id<YFNoteListDataService>)service { if (self = [super init]) { self.noteListDataService = service; } return self; } #pragma mark - Public #pragma mark - Private - (NSArray<YFNoteModel *> *)noteList { return self.noteListDataService.noteList; } #pragma mark - YFViperInteractor #pragma mark - YFNoteListInteractorInput - (void)loadAllNotes { [self.noteListDataService fetchAllNotesWithCompletion:^(NSArray *notes) { NSLog(@"count = %d", self.noteList.count); }]; } - (NSInteger)noteCount { return self.noteList.count; } - (NSString *)titleForNoteAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return nil; } return self.noteList[idx].title; } - (NSString *)contentForNoteAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return nil; } return self.noteList[idx].content; } - (YFNoteModel *)noteAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return nil; } return self.noteList[idx]; } - (NSString *)noteUUIDAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return nil; } return self.noteList[idx].uuid; } - (NSString *)noteTitleAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return nil; } return self.noteList[idx].title; } - (NSString *)noteContentAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return nil; } return self.noteList[idx].content; } - (void)deleteNoteAtIndex:(NSUInteger)idx { if (self.noteList.count - 1 < idx) { return; } YFNoteModel *note = [self noteAtIndex:idx]; [self.noteListDataService deleteNote:note]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Interactor/YFNoteListInteractor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
566
```objective-c // // YFNoteListViewDataSource.h // BigShow1949 // // Created by big show on 2018/10/18. // #import <Foundation/Foundation.h> @protocol YFNoteListViewDataSource <NSObject> - (NSInteger)numberOfRowsInSection:(NSInteger)section; - (NSString *)textOfCellForRowAtIndexPath:(NSIndexPath *)indexPath; - (NSString *)detailTextOfCellForRowAtIndexPath:(NSIndexPath *)indexPath; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/View/YFNoteListViewDataSource.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
92
```objective-c // // YFNoteListViewEventHandler.h // BigShow1949 // // Created by big show on 2018/10/18. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "YFViperViewEventHandler.h" @protocol YFNoteListViewEventHandler <YFViperViewEventHandler,UIViewControllerPreviewingDelegate> - (void)didTouchNavigationBarAddButton; - (BOOL)canEditRowAtIndexPath:(NSIndexPath *)indexPath; - (void)handleDeleteCellForRowAtIndexPath:(NSIndexPath *)indexPath; - (void)handleDidSelectRowAtIndexPath:(NSIndexPath *)indexPath; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/View/YFNoteListViewEventHandler.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
126
```objective-c // // YFNoteListViewController.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFNoteListViewController.h" #import "YFNoteListViewDataSource.h" #import "YFNoteListViewEventHandler.h" #import "YFViperViewPrivate.h" // @interface YFNoteListViewController ()<YFViperViewPrivate,UITableViewDelegate,UITableViewDataSource> @property (nonatomic, strong) id<YFNoteListViewEventHandler> eventHandler; @property (nonatomic, strong) id<YFNoteListViewDataSource> viewDataSource; @end @implementation YFNoteListViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"NoteList"; self.view.backgroundColor = [UIColor whiteColor]; [self setupNav]; } - (UIViewController *)routeSource { return self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if ([self.eventHandler respondsToSelector:@selector(handleViewWillAppear:)]) { [self.eventHandler handleViewWillAppear:animated]; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([self.eventHandler respondsToSelector:@selector(handleViewDidAppear:)]) { [self.eventHandler handleViewDidAppear:animated]; } } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if ([self.eventHandler respondsToSelector:@selector(viewWillDisappear:)]) { [self.eventHandler handleViewWillDisappear:animated]; } } #pragma mark UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.viewDataSource numberOfRowsInSection:section]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *text = [self.viewDataSource textOfCellForRowAtIndexPath:indexPath]; NSString *detailText = [self.viewDataSource detailTextOfCellForRowAtIndexPath:indexPath]; UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath text:text detailText:detailText]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return [self.eventHandler canEditRowAtIndexPath:indexPath]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.eventHandler handleDeleteCellForRowAtIndexPath:indexPath]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; [self.eventHandler handleDidSelectRowAtIndexPath:indexPath]; } #pragma mark - YFNoteListViewProtocol //- (UITableView *)noteListTableView {} - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath text:(NSString *)text detailText:(NSString *)detailText { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"noteListCell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"noteListCell"]; } cell.textLabel.text = text; cell.detailTextLabel.text = detailText; return cell; } #pragma mark - Private - (void)setupNav { UIBarButtonItem *addNoteItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self.eventHandler action:@selector(didTouchNavigationBarAddButton)]; self.navigationItem.rightBarButtonItem = addNoteItem; if ([self.eventHandler respondsToSelector:@selector(handleViewReady)]) { [self.eventHandler handleViewReady]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/View/YFNoteListViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
760
```objective-c // // YFNoteListViewPresenter.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <Foundation/Foundation.h> //#import "YFViperViewEventHandler.h" #import "YFViperPresenter.h" #import "YFNoteListViewDataSource.h" #import "YFNoteListViewEventHandler.h" @interface YFNoteListViewPresenter : NSObject<YFViperPresenter,YFNoteListViewEventHandler,YFNoteListViewDataSource> @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Presenter/YFNoteListViewPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
106
```objective-c // // YFNoteListViewController.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <UIKit/UIKit.h> #import "YFNoteListViewProtocol.h" #import "YFViperView.h" @interface YFNoteListViewController : UITableViewController<YFViperView,YFNoteListViewProtocol> @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/View/YFNoteListViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
81
```objective-c // // YFNoteListWireframe.m // BigShow1949 // // Created by big show on 2018/10/17. // #import "YFNoteListWireframe.h" #import <objc/runtime.h> #import "YFViperView.h" #import "YFNoteListRouter.h" #import "YFRouter.h" #import "YFViperWireframePrivate.h" #import "YFRouter+YFEditor.h" #import "YFRouter+YFLogin.h" // YFViperWireframePrivate viewrouter @interface YFNoteListWireframe()<YFViperWireframePrivate> @property (nonatomic, weak) id<YFViperView> view; //@property (nonatomic, strong) id<YFNoteListRouter> router; @property (nonatomic, strong) id router; // <YFNoteListRouter> @property (nonatomic, weak) UIViewController *editor; @property (nonatomic, assign) BOOL presentingEditor; @property (nonatomic, assign) BOOL pushedEditor; @end @implementation YFNoteListWireframe #pragma mark - YFNoteListWireframeInput - (void)presentEditorForCreatingNewNoteWithDelegate:(id<YFEditorDelegate>)delegate completion:(void (^ __nullable)(void))completion { UIViewController *editorViewController = [[self.router class] viewForCreatingNoteWithDelegate:delegate]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:editorViewController]; NSLog(@"routeSoure = %@ , editorVC = %@", [self.view.routeSource class], [editorViewController class]); [[self.router class] presentViewController:navigationController fromViewController:self.view.routeSource animated:YES completion:completion]; [self resetState]; self.editor = editorViewController; self.presentingEditor = YES; } - (void)quitEditorViewWithAnimated:(BOOL)animated { if (self.presentingEditor) { self.presentingEditor = NO; [[self.router class] dismissViewController:self.editor animated:animated completion:nil]; } else if (self.pushedEditor) { self.pushedEditor = NO; [[self.router class] popViewController:self.editor animated:animated]; } } - (void)pushEditorViewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<YFEditorDelegate>)delegate { UIViewController *editorViewController = [[self.router class] viewForEditingNoteWithUUID:uuid title:title content:content delegate:delegate]; // editorViewController = (null), routerSource = <YFNoteListViewController: 0x7fcd26d3c6e0> NSLog(@"editorViewController = %@, routerSource = %@", editorViewController, self.view.routeSource); [[self.router class] pushViewController:editorViewController fromViewController:self.view.routeSource animated:YES]; [self resetState]; self.editor = editorViewController; self.pushedEditor = YES; } - (void)presentLoginViewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate completion:(void (^ __nullable)(void))completion { UIViewController *loginViewController = [[self.router class] loginViewWithMessage:message delegate:delegate]; NSLog(@"routeSource = %@", self.view.routeSource); [[self.router class] presentViewController:loginViewController fromViewController:self.view.routeSource animated:YES completion:completion]; } - (void)resetState { self.editor = nil; self.presentingEditor = NO; self.pushedEditor = NO; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Wireframe/YFNoteListWireframe.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
739
```objective-c // // YFNoteListViewPresenter.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFNoteListViewPresenter.h" #import "YFViperView.h" #import "YFNoteListWireframeInput.h" // inputYFNoteListWireframe.h,.h #import "YFViperInteractor.h" #import "YFNoteListInteractorInput.h" //#import "YFNoteListInteractor.h" #import "YFNoteListViewProtocol.h" #import "YFEditorDelegate.h" #import "YFLoginViewDelegate.h" @interface YFNoteListViewPresenter ()<YFEditorDelegate,YFLoginViewDelegate> @property (nonatomic, weak) id<YFViperView,YFNoteListViewProtocol>view; // YFViperWireframePrivatewireframe YFNoteListWireframeInput @property (nonatomic, strong) id<YFNoteListWireframeInput> wireframe; @property (nonatomic, strong) id<YFViperInteractor,YFNoteListInteractorInput> interactor; @property (nonatomic, assign) BOOL logined; @end @implementation YFNoteListViewPresenter #pragma mark - YFViperPresenter #pragma mark - YFNoteListViewEventHandler - (void)didTouchNavigationBarAddButton { [self.wireframe presentEditorForCreatingNewNoteWithDelegate:self completion:nil]; } - (BOOL)canEditRowAtIndexPath:(NSIndexPath *)indexPath {return YES;} - (void)handleDeleteCellForRowAtIndexPath:(NSIndexPath *)indexPath{ [self.interactor deleteNoteAtIndex:indexPath.row]; } - (void)handleDidSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *uuid = [self.interactor noteUUIDAtIndex:indexPath.row]; NSString *title = [self.interactor noteTitleAtIndex:indexPath.row]; NSString *content = [self.interactor noteContentAtIndex:indexPath.row]; NSLog(@"uuid = %@, title = %@, contet = %@", uuid, title, content); [self.wireframe pushEditorViewForEditingNoteWithUUID:uuid title:title content:content delegate:self]; } #pragma mark - YFViperViewEventHandler - (void)handleViewReady { // nil [self.interactor loadAllNotes]; } - (void)handleViewRemoved {} - (void)handleViewWillAppear:(BOOL)animated {} - (void)handleViewDidAppear:(BOOL)animated { if (!self.logined) { [self.wireframe presentLoginViewWithMessage:@"login with message" delegate:self completion:nil]; } } - (void)handleViewWillDisappear:(BOOL)animated {} - (void)handleViewDidDisappear:(BOOL)animated {} #pragma mark - YFEditorDelegate - (void)editor:(UIViewController *)editor didFinishEditNote:(YFNoteModel *)note { [self.wireframe quitEditorViewWithAnimated:YES]; [self.view.tableView reloadData]; } #pragma mark - YFNoteListViewDataSource - (NSInteger)numberOfRowsInSection:(NSInteger)section { return [self.interactor noteCount]; } - (NSString *)textOfCellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *title = [self.interactor titleForNoteAtIndex:indexPath.row]; return title; } - (NSString *)detailTextOfCellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *content = [self.interactor contentForNoteAtIndex:indexPath.row]; return content; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Presenter/YFNoteListViewPresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
717
```objective-c // // YFNoteListWireframeInput.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFNoteListWireframeInput_h #define YFNoteListWireframeInput_h @protocol YFEditorDelegate,YFLoginViewDelegate; @protocol YFNoteListWireframeInput - (void)presentLoginViewWithMessage:(NSString *)message delegate:(id<YFLoginViewDelegate>)delegate completion:(void (^ __nullable)(void))completion; - (void)presentEditorForCreatingNewNoteWithDelegate:(id<YFEditorDelegate>)delegate completion:(void (^ __nullable)(void))completion; - (void)quitEditorViewWithAnimated:(BOOL)animated; - (void)pushEditorViewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<YFEditorDelegate>)delegate; @end #endif /* YFNoteListWireframeInput_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Wireframe/YFNoteListWireframeInput.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
207
```objective-c // // YFNoteListRouter.h // BigShow1949 // // Created by big show on 2018/12/9. // #ifndef YFNoteListRouter_h #define YFNoteListRouter_h #import "YFViperRouter.h" @protocol YFEditorDelegate; @protocol YFNoteListRouter<YFViperRouter> //+ (UIViewController *)loginViewWithMessage:(NSString *)message delegate:(id<ZIKTLoginViewDelegate>)delegate; //+ (UIViewController *)viewForCreatingNoteWithDelegate:(id<YFEditorDelegate>)delegate; //+ (UIViewController *)viewForEditingNoteWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content delegate:(id<ZIKTEditorDelegate>)delegate; @end #endif /* YFNoteListRouter_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Wireframe/YFNoteListRouter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
174
```objective-c // // YFNoteListWireframe.h // BigShow1949 // // Created by big show on 2018/10/17. // #import <Foundation/Foundation.h> #import "YFViperWireframe.h" // YFNoteListWireframeInput YFNoteListWireframeInput @protocol YFEditorDelegate,YFLoginViewDelegate;// @interface YFNoteListWireframe : NSObject <YFViperWireframe> - (void)presentEditorForCreatingNewNoteWithDelegate:(id<YFEditorDelegate>)delegate completion:(void (^ __nullable)(void))completion; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Wireframe/YFNoteListWireframe.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
131
```objective-c // // YFTNoteListModuleBuilder.h // BigShow1949 // // Created by big show on 2018/10/16. // #import <Foundation/Foundation.h> @protocol YFViperViewPrivate,YFNoteListDataService,YFNoteListRouter; @interface YFTNoteListModuleBuilder : NSObject + (UIViewController *)viewControllerWithNoteListDataService:(id<YFViperViewPrivate>)service router:(id<YFNoteListRouter>)router; + (void)buildView:(id<YFViperViewPrivate>)view noteListDataService:(id<YFNoteListDataService>)service router:(id<YFNoteListRouter>)router; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Builder/YFTNoteListModuleBuilder.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
146
```objective-c // // YFTNoteListModuleBuilder.m // BigShow1949 // // Created by big show on 2018/10/16. // #import "YFTNoteListModuleBuilder.h" #import "YFNoteListInteractor.h" #import "YFNoteListViewPresenter.h" #import "YFNoteListViewController.h" #import "YFNoteListWireframe.h" #import "YFViperViewPrivate.h" // #import "YFViperWireframePrivate.h" #import "YFViperPresenterPrivate.h" @implementation YFTNoteListModuleBuilder + (UIViewController *)viewControllerWithNoteListDataService:(id<YFViperViewPrivate>)service router:(id<YFNoteListRouter>)router { return nil; } + (void)buildView:(id<YFViperViewPrivate>)view noteListDataService:(id<YFNoteListDataService>)service router:(id<YFNoteListRouter>)router { // YFNoteListViewPresenter *presenter = [[YFNoteListViewPresenter alloc] init]; YFNoteListInteractor *interactor = [[YFNoteListInteractor alloc] initWithNoteListDataService:service]; interactor.eventHandler = presenter; interactor.dataSource = presenter; id<YFViperWireframePrivate>wireframe = (id)[[YFNoteListWireframe alloc] init]; // viewweakrouterstrong wireframe.view = view; wireframe.router = router; // viewweakwireframeinteractorstrong [(id<YFViperPresenterPrivate>)presenter setView:view]; [(id<YFViperPresenterPrivate>)presenter setWireframe:wireframe]; [(id<YFViperPresenterPrivate>)presenter setInteractor:interactor]; // presenter view.eventHandler = presenter; view.viewDataSource = presenter; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Builder/YFTNoteListModuleBuilder.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
411
```objective-c // // YFNoteModel.m // BigShow1949 // // Created by big show on 2018/12/9. // #import "YFNoteModel.h" @interface YFNoteModel () @property (nonatomic, copy) NSString *uuid; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *content; @end @implementation YFNoteModel - (instancetype)initWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content { NSParameterAssert(uuid.length > 0); NSParameterAssert(title); NSParameterAssert(content); if (self = [super init]) { _uuid = uuid; _title = title; _content = content; } return self; } - (instancetype)initWithNewNoteForTitle:(NSString *)title content:(NSString *)content { return [self initWithUUID:[NSUUID UUID].UUIDString title:title content:content]; } - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.uuid forKey:@"uuid"]; [aCoder encodeObject:self.title forKey:@"title"]; [aCoder encodeObject:self.content forKey:@"content"]; } - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { self.uuid = [aDecoder decodeObjectForKey:@"uuid"]; self.title = [aDecoder decodeObjectForKey:@"title"]; self.content = [aDecoder decodeObjectForKey:@"content"]; return self; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Enity/YFNoteModel.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
313
```objective-c // // YFViperTableListViewController.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFViperTableListViewController.h" #import "YFCategoryTableWireframe.h" #import "YFCategoryTablePresenter.h" #import "YFCategoryTableInteractor.h" #import "YFCategoryTableViewController.h" @interface YFViperTableListViewController () //@property (nonatomic, strong) YFCategoryTableWireframe *wireframe; //@property (nonatomic, strong) YFCategoryTableViewController *viewController; @end @implementation YFViperTableListViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; UIButton *redBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 80, 44)]; [redBtn setTitle:@"Button" forState:UIControlStateNormal]; [redBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside]; redBtn.titleLabel.textColor = [UIColor blackColor]; redBtn.backgroundColor = [UIColor blueColor]; [self.view addSubview:redBtn]; } - (void)buttonClick { YFCategoryTableViewController *viewController = [[YFCategoryTableViewController alloc] init]; YFCategoryTablePresenter *presenter = [YFCategoryTablePresenter new]; YFCategoryTableWireframe *wireframe = [YFCategoryTableWireframe new]; YFCategoryTableInteractor *interactor = [YFCategoryTableInteractor new]; presenter.wireframe = wireframe; presenter.interactor = interactor; presenter.categoryView = viewController; wireframe.presenter = presenter; viewController.presenter = presenter; [wireframe pushViewController:viewController fromViewController:self]; } - (void)dealloc { NSLog(@"YFViperTableListViewController----dealloc"); } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/YFViperTableListViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
392
```objective-c // // YFNoteModel.h // BigShow1949 // // Created by big show on 2018/12/9. // #import <Foundation/Foundation.h> @interface YFNoteModel : NSObject<NSCoding> @property (nonatomic, readonly, copy) NSString *uuid; @property (nonatomic, readonly, copy) NSString *title; @property (nonatomic, readonly, copy) NSString *content; - (instancetype)initWithUUID:(NSString *)uuid title:(NSString *)title content:(NSString *)content NS_DESIGNATED_INITIALIZER; - (instancetype)initWithNewNoteForTitle:(NSString *)title content:(NSString *)content; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/Note/NoteListModule/Enity/YFNoteModel.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
132
```objective-c // // YFCategoryTableInteractor.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @interface YFCategoryTableInteractor : NSObject -(NSMutableArray*)getAllCategories; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableInteractor.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
60
```objective-c // // YFCategoryTableViewControllerProtocol.h // BigShow1949 // // Created by big show on 2018/12/8. // #ifndef YFCategoryTableViewControllerProtocol_h #define YFCategoryTableViewControllerProtocol_h @protocol YFCategoryTableViewControllerDelegate @required - (void)updateTableView:(NSArray *)array; @end #endif /* YFCategoryTableViewControllerProtocol_h */ ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableViewControllerProtocol.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
88
```objective-c // // YFCategoryTableViewController.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <UIKit/UIKit.h> #import "YFCategoryTableViewControllerProtocol.h" @class YFCategoryTablePresenter; @interface YFCategoryTableViewController : UITableViewController<YFCategoryTableViewControllerDelegate> @property (nonatomic, strong) YFCategoryTablePresenter *presenter; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
91
```objective-c // // YFViperTableListViewController.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <UIKit/UIKit.h> @interface YFViperTableListViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/YFViperTableListViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
56
```objective-c // // YFCategoryTableWireframe.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @class YFCategoryTablePresenter; @interface YFCategoryTableWireframe : NSObject @property (nonatomic, strong) YFCategoryTablePresenter *presenter; //- (void)presentInterfaceFromController:(UINavigationController *)navigationController; - (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source; - (void)jumpToNews:(int)categoryIndex; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableWireframe.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
120
```objective-c // // YFCategoryTableInteractor.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFCategoryTableInteractor.h" #import "YFCategoryDisplayItem.h" @implementation YFCategoryTableInteractor -(NSMutableArray*)getAllCategories { YFCategoryDisplayItem *item0 = [YFCategoryDisplayItem itemWithTitle:@"0"]; YFCategoryDisplayItem *item1 = [YFCategoryDisplayItem itemWithTitle:@"1"]; YFCategoryDisplayItem *item2 = [YFCategoryDisplayItem itemWithTitle:@"2"]; YFCategoryDisplayItem *item3 = [YFCategoryDisplayItem itemWithTitle:@"3"]; YFCategoryDisplayItem *item4 = [YFCategoryDisplayItem itemWithTitle:@"4"]; return @[item0,item1,item2,item3,item4]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableInteractor.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
191
```objective-c // // YFCategoryTablePresenter.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFCategoryTablePresenter.h" #import "YFCategoryTableViewControllerProtocol.h" #import "YFCategoryTableInteractor.h" #import "YFCategoryTableWireframe.h" @implementation YFCategoryTablePresenter - (void)configureData { NSArray *arr = [self.interactor getAllCategories]; [self.categoryView updateTableView:arr]; } - (void)jumpToNews:(int)categoryIndex { [self.wireframe jumpToNews:categoryIndex]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTablePresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
140
```objective-c // // YFCategoryDisplayItem.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFCategoryDisplayItem.h" @implementation YFCategoryDisplayItem + (instancetype)itemWithTitle:(NSString *)title { YFCategoryDisplayItem *item = [[YFCategoryDisplayItem alloc] init]; item.title = title; return item; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryDisplayItem.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
93
```objective-c // // YFCategoryDisplayItem.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @interface YFCategoryDisplayItem : NSObject @property (nonatomic, copy) NSString *title; + (instancetype)itemWithTitle:(NSString *)title; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryDisplayItem.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
72
```objective-c // // YFCategoryTableViewController.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFCategoryTableViewController.h" #import "YFCategoryTablePresenter.h" #import "YFCategoryDisplayItem.h" @interface YFCategoryTableViewController () @property (nonatomic,strong) NSMutableArray *dataArr; @end @implementation YFCategoryTableViewController - (void)viewDidLoad { [super viewDidLoad]; [self.presenter configureData]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test1"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test1"]; } cell.textLabel.text = [NSString stringWithFormat:@"row = %ld", (long)indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.presenter jumpToNews:indexPath.row]; } #pragma mark - YFCategoryTableViewControllerDelegate - (void)updateTableView:(NSArray *)array { self.dataArr = [NSMutableArray arrayWithArray:array]; [self.tableView reloadData]; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } */ /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
598
```objective-c // // YFCategoryTableWireframe.m // BigShow1949 // // Created by big show on 2018/12/8. // #import "YFCategoryTableWireframe.h" #import "YFCategoryTableViewController.h" @implementation YFCategoryTableWireframe - (void)pushViewController:(UIViewController *)destination fromViewController:(UIViewController *)source { [source.navigationController pushViewController:destination animated:YES]; } - (void)jumpToNews:(int)categoryIndex { // /* YFCategoryTableViewController *viewController = [[YFCategoryTableViewController alloc] init]; YFCategoryTablePresenter *presenter = [YFCategoryTablePresenter new]; YFCategoryTableWireframe *wireframe = [YFCategoryTableWireframe new]; YFCategoryTableInteractor *interactor = [YFCategoryTableInteractor new]; presenter.wireframe = wireframe; presenter.interactor = interactor; presenter.categoryView = viewController; wireframe.presenter = presenter; viewController.presenter = presenter; [wireframe pushViewController:viewController fromViewController:self]; */ } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTableWireframe.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
241
```objective-c // // HomePresenter.m // MVP // // Created by baoshan on 17/2/8. // #import "HomePresenter.h" #import "HomeModel.h" #import "YYModel.h" @interface HomePresenter() @end @implementation HomePresenter - (void)getMovieListWithUrlString:(NSString *)urlString{ [self.httpClient get:urlString parameters:nil]; } #pragma mark - HttpResponseHandle - (void)onSuccess:(id)responseObject{ // HomeModel *model = [HomeModel yy_modelWithJSON:responseObject]; if ([_view respondsToSelector:@selector(onGetMovieListSuccess:)]) { [_view onGetMovieListSuccess:model]; } } - (void)onFail:(id)clientInfo errCode:(NSInteger)errCode errInfo:(NSString *)errInfo{ if ([_view respondsToSelector: @selector(onGetMovieListFail: des:)]) { [_view onGetMovieListFail:errCode des:errInfo]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/HomePresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
212
```objective-c // // HomeModel.h // MVP // // Created by baoshan on 17/2/8. // #import <Foundation/Foundation.h> @interface HomeModel : NSObject @property (nonatomic,assign)NSInteger count; @property (nonatomic,assign)NSInteger start; @property (nonatomic,assign)NSInteger total; @property (nonatomic,assign)NSArray *books; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/HomeModel.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
76
```objective-c // // YFCategoryTablePresenter.h // BigShow1949 // // Created by big show on 2018/12/8. // #import <Foundation/Foundation.h> @protocol YFCategoryTableViewControllerDelegate; @class YFCategoryTableWireframe; @class YFCategoryTableInteractor; @interface YFCategoryTablePresenter : NSObject @property (nonatomic, weak) id<YFCategoryTableViewControllerDelegate> categoryView; @property (nonatomic, strong) YFCategoryTableWireframe *wireframe; @property (nonatomic, strong) YFCategoryTableInteractor *interactor; - (void)configureData; - (void)jumpToNews:(int)categoryIndex; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Viper/TableList/Category/YFCategoryTablePresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
146
```objective-c // // MVPHomeViewController.h // BigShow1949 // // Created by apple on 17/8/11. // #import <UIKit/UIKit.h> @interface MVPHomeViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/MVPHomeViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // HomeViewProtocol.h // MVP // // Created by baoshan on 17/2/8. // #import <Foundation/Foundation.h> #import "HomeModel.h" @protocol HomeViewProtocol <NSObject> - (void)onGetMovieListSuccess:(HomeModel *)homeModel; - (void)onGetMovieListFail:(NSInteger) errorCode des:(NSString *)des; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/HomeViewProtocol.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
86
```objective-c // // HomePresenter.h // MVP // // Created by baoshan on 17/2/8. // #import "HttpPresenter.h" #import "HomeViewProtocol.h" @interface HomePresenter : HttpPresenter <id<HomeViewProtocol>> - (void)getMovieListWithUrlString:(NSString *)urlString; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/HomePresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
72
```objective-c // // HomeModel.m // MVP // // Created by baoshan on 17/2/8. // #import "HomeModel.h" @implementation HomeModel @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/HomeModel.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
41
```objective-c // // MVPHomeViewController.m // BigShow1949 // // Created by apple on 17/8/11. // #import "MVPHomeViewController.h" #import "HomePresenter.h" #import "HomeViewProtocol.h" @interface MVPHomeViewController ()<HomeViewProtocol> @property (nonatomic,strong)HomePresenter *homePresenter; @end @implementation MVPHomeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; [self setupData]; } - (void)setupData{ /* path_to_url# */ _homePresenter = [[HomePresenter alloc] initWithView:self]; [_homePresenter getMovieListWithUrlString:@"path_to_url"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - HomeViewProtocol - (void)onGetMovieListSuccess:(HomeModel *)homeModel{ UIAlertController *alertCtl = [UIAlertController alertControllerWithTitle:@"result" message:@"request success" preferredStyle:UIAlertControllerStyleActionSheet]; [self presentViewController:alertCtl animated:YES completion:nil]; } - (void)onGetMovieListFail:(NSInteger)errorCode des:(NSString *)des{ UIAlertController *alertCtl = [UIAlertController alertControllerWithTitle:@"result" message:@"request fail" preferredStyle:UIAlertControllerStyleActionSheet]; [self presentViewController:alertCtl animated:YES completion:nil]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/MVPHomeViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
308
```objective-c // // HttpClient.h // MVP // // Created by baoshan on 17/2/8. // #import <Foundation/Foundation.h> @protocol HttpResponseHandle; @interface HttpClient : NSObject // - (instancetype)initWithHandle:(id<HttpResponseHandle>) responseHandle; - (void)post:(NSString *)URLString parameters:(id)parameters; - (void)get:(NSString *)URLString parameters:(id)parameters; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/HttpClient.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
91
```objective-c /* See LICENSE.txt for this samples licensing information Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. */ #import <Foundation/Foundation.h> #import <SystemConfiguration/SystemConfiguration.h> #import <netinet/in.h> typedef enum : NSInteger { NotReachable = 0, ReachableViaWiFi, ReachableViaWWAN } NetworkStatus; extern NSString *kReachabilityChangedNotification; @interface Reachability : NSObject /*! * Use to check the reachability of a given host name. */ + (instancetype)reachabilityWithHostName:(NSString *)hostName; /*! * Use to check the reachability of a given IP address. */ + (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress; /*! * Checks whether the default route is available. Should be used by applications that do not connect to a particular host. */ + (instancetype)reachabilityForInternetConnection; /*! * Checks whether a local WiFi connection is available. */ + (instancetype)reachabilityForLocalWiFi; /*! * Start listening for reachability notifications on the current run loop. */ - (BOOL)startNotifier; - (void)stopNotifier; - (NetworkStatus)currentReachabilityStatus; /*! * WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand. */ - (BOOL)connectionRequired; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/Reachability.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
288
```objective-c // // HttpClient.m // MVP // // Created by baoshan on 17/2/8. // #import "HttpClient.h" #import "AFNetworking.h" #import "HttpResponseHandle.h" #import "Reachability.h" @interface HttpClient () /** */ @property (nonatomic,weak) id<HttpResponseHandle> responseHandle; /** */ @property (nonatomic,strong) Reachability *netReachability; /** */ @property (nonatomic,strong) AFHTTPSessionManager *sessionManager; @end @implementation HttpClient /** */ - (instancetype)initWithHandle:(id<HttpResponseHandle>)responseHandle { self = [super init]; if (self) { //delegate _responseHandle = responseHandle; _netReachability = [Reachability reachabilityForInternetConnection]; } return self; } - (void)post:(NSString *)URLString parameters:(id)parameters { [self.sessionManager POST:URLString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) { // if([_responseHandle respondsToSelector:@selector(onSuccess:)]){ [_responseHandle onSuccess:responseObject]; } } failure:^(NSURLSessionDataTask *task, NSError *error) { if ([_responseHandle respondsToSelector:@selector(onFail:errCode:errInfo:)]) { [_responseHandle onFail:parameters errCode:error.code errInfo:error.description]; } }]; } - (void)get:(NSString *)URLString parameters:(id)parameters{ // if ([_netReachability currentReachabilityStatus] == NotReachable) { if (_responseHandle) { //netcode [_responseHandle onFail:parameters errCode:0 errInfo:@"Network is not reachable"]; } return ; } [self.sessionManager GET:URLString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) { // if([_responseHandle respondsToSelector:@selector(onSuccess:)]){ [_responseHandle onSuccess:responseObject]; } } failure:^(NSURLSessionDataTask *task, NSError *error) { if ([_responseHandle respondsToSelector:@selector(onFail:errCode:errInfo:)]) { [_responseHandle onFail:parameters errCode:error.code errInfo:error.description]; } }]; } #pragma mark - lazy load - (AFHTTPSessionManager *)sessionManager{ if (!_sessionManager) { _sessionManager = [AFHTTPSessionManager manager]; // k-v _sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; _sessionManager.responseSerializer = [AFJSONResponseSerializer serializer]; _sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil]; } return _sessionManager; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/HttpClient.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
591
```objective-c // // HttpPresenter.h // MVP // // Created by baoshan on 17/2/8. // #import "Presenter.h" #import "HttpResponseHandle.h" #import "HttpClient.h" @interface HttpPresenter<E> : Presenter<E> <HttpResponseHandle> @property (nonatomic,strong)HttpClient *httpClient; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/HttpPresenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
69
```objective-c // // HttpResponseHandle.h // MVP // // Created by baoshan on 17/2/8. // #import <Foundation/Foundation.h> @protocol HttpResponseHandle <NSObject> @required /** @param responseObject */ - (void)onSuccess:(id)responseObject; /** @param clientInfo @param errCode @param errInfo */ - (void)onFail:(id)clientInfo errCode:(NSInteger)errCode errInfo:(NSString *)errInfo; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/HttpResponseHandle.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
112
```objective-c // // HttpPresenter.m // MVP // // Created by baoshan on 17/2/8. // #import "HttpPresenter.h" @implementation HttpPresenter - (instancetype) initWithView:(id)view{ if (self = [super initWithView:view]) { _httpClient = [[HttpClient alloc] initWithHandle:self]; } return self; } #pragma mark - HttpResponseHandle - (void)onSuccess:(id)responseObject{ } - (void)onFail:(id)clientInfo errCode:(NSInteger)errCode errInfo:(NSString *)errInfo{ } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/HttpPresenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
128
```objective-c // // Presenter.h // MVP // // Created by baoshan on 17/2/8. // #import <Foundation/Foundation.h> @interface Presenter<E>: NSObject{ //MVP __weak E _view; } /** @param view */ - (instancetype) initWithView:(E)view; /** * * @param view */ - (void) attachView:(E)view ; /** */ - (void)detachView; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/presenter/Presenter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
101
```objective-c // // Presenter.m // MVP // // Created by baoshan on 17/2/8. // #import "Presenter.h" @implementation Presenter /** */ - (instancetype)initWithView:(id)view{ if (self = [super init]) { _view = view; } return self; } /** * * @param view */ - (void) attachView:(id)view { _view = view; } /** */ - (void)detachView{ _view = nil; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/presenter/Presenter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
116
```objective-c // // CustomTableViewCell.h // MVVMDemo // // Created by coderyi on 15/6/28. // #import <UIKit/UIKit.h> @interface YiCustomTableViewCell : UITableViewCell @property(nonatomic,strong) UILabel *titleLabel; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/View/YiCustomTableViewCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
55
```objective-c // // CustomTableViewCell.m // MVVMDemo // // Created by coderyi on 15/6/28. // #import "YiCustomTableViewCell.h" @implementation YiCustomTableViewCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code _titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, YFScreen.width, 50)]; [self.contentView addSubview:_titleLabel]; _titleLabel.backgroundColor=[UIColor whiteColor]; _titleLabel.font=[UIFont systemFontOfSize:14]; } return self; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/View/YiCustomTableViewCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
146
```objective-c // // TableViewModel.h // MVVMDemo // // Created by coderyi on 15/6/28. // #import <Foundation/Foundation.h> typedef void (^callback) (NSArray *array); @interface YiTableViewModel : NSObject //tableView - (void)headerRefreshRequestWithCallback:(callback)callback; //tableView - (void)footerRefreshRequestWithCallback:(callback)callback; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/ViewModel/YiTableViewModel.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
91
```objective-c // // TableViewModel.m // MVVMDemo // // Created by coderyi on 15/6/28. // #import "YiTableViewModel.h" #import "YiCustomModel.h" @interface YiTableViewModel () @end @implementation YiTableViewModel - (instancetype)init { self = [super init]; if (self) { } return self; } - (void)headerRefreshRequestWithCallback:(callback)callback { // dispatch_async(dispatch_get_global_queue(0, 0), ^{ sleep(2); dispatch_async(dispatch_get_main_queue(), ^{ // NSMutableArray *arr=[NSMutableArray array]; for (int i=0; i<16; i++) { int x = arc4random() % 100; NSString *string=[NSString stringWithFormat:@" (random%d) ",x]; YiCustomModel *model=[[YiCustomModel alloc] init]; model.title=string; [arr addObject:model]; } callback(arr); }); }); } - (void )footerRefreshRequestWithCallback:(callback)callback { // dispatch_async(dispatch_get_global_queue(0, 0), ^{ sleep(2); dispatch_async(dispatch_get_main_queue(), ^{ // NSMutableArray *arr=[NSMutableArray array]; for (int i=0; i<16; i++) { int x = arc4random() % 100; NSString *string=[NSString stringWithFormat:@" (random%d) ",x]; YiCustomModel *model=[[YiCustomModel alloc] init]; model.title=string; [arr addObject:model]; } callback(arr); }); }); } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/ViewModel/YiTableViewModel.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
365
```objective-c /* See LICENSE.txt for this samples licensing information Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. */ #import <arpa/inet.h> #import <ifaddrs.h> #import <netdb.h> #import <sys/socket.h> #import <CoreFoundation/CoreFoundation.h> #import "Reachability.h" NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification"; #pragma mark - Supporting functions #define kShouldPrintReachabilityFlags 0 static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) { #if kShouldPrintReachabilityFlags NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n", (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-', comment ); #endif } static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) { #pragma unused (target, flags) NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); NSCAssert([(__bridge NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); Reachability* noteObject = (__bridge Reachability *)info; // Post a notification to notify the client that the network reachability changed. [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject]; } #pragma mark - Reachability implementation @implementation Reachability { BOOL _alwaysReturnLocalWiFiStatus; //default is NO SCNetworkReachabilityRef _reachabilityRef; } + (instancetype)reachabilityWithHostName:(NSString *)hostName { Reachability* returnValue = NULL; SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); if (reachability != NULL) { returnValue= [[self alloc] init]; if (returnValue != NULL) { returnValue->_reachabilityRef = reachability; returnValue->_alwaysReturnLocalWiFiStatus = NO; } else { CFRelease(reachability); } } return returnValue; } + (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress { SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)hostAddress); Reachability* returnValue = NULL; if (reachability != NULL) { returnValue = [[self alloc] init]; if (returnValue != NULL) { returnValue->_reachabilityRef = reachability; returnValue->_alwaysReturnLocalWiFiStatus = NO; } else { CFRelease(reachability); } } return returnValue; } + (instancetype)reachabilityForInternetConnection { struct sockaddr_in zeroAddress; bzero(&zeroAddress, sizeof(zeroAddress)); zeroAddress.sin_len = sizeof(zeroAddress); zeroAddress.sin_family = AF_INET; return [self reachabilityWithAddress:&zeroAddress]; } + (instancetype)reachabilityForLocalWiFi { struct sockaddr_in localWifiAddress; bzero(&localWifiAddress, sizeof(localWifiAddress)); localWifiAddress.sin_len = sizeof(localWifiAddress); localWifiAddress.sin_family = AF_INET; // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0. localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); Reachability* returnValue = [self reachabilityWithAddress: &localWifiAddress]; if (returnValue != NULL) { returnValue->_alwaysReturnLocalWiFiStatus = YES; } return returnValue; } #pragma mark - Start and stop notifier - (BOOL)startNotifier { BOOL returnValue = NO; SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) { if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) { returnValue = YES; } } return returnValue; } - (void)stopNotifier { if (_reachabilityRef != NULL) { SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); } } - (void)dealloc { [self stopNotifier]; if (_reachabilityRef != NULL) { CFRelease(_reachabilityRef); } } #pragma mark - Network Flag Handling - (NetworkStatus)localWiFiStatusForFlags:(SCNetworkReachabilityFlags)flags { PrintReachabilityFlags(flags, "localWiFiStatusForFlags"); NetworkStatus returnValue = NotReachable; if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) { returnValue = ReachableViaWiFi; } return returnValue; } - (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags { PrintReachabilityFlags(flags, "networkStatusForFlags"); if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) { // The target host is not reachable. return NotReachable; } NetworkStatus returnValue = NotReachable; if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) { /* If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi... */ returnValue = ReachableViaWiFi; } if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) { /* ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs... */ if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) { /* ... and no [user] intervention is needed... */ returnValue = ReachableViaWiFi; } } if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) { /* ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. */ returnValue = ReachableViaWWAN; } return returnValue; } - (BOOL)connectionRequired { NSAssert(_reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef"); SCNetworkReachabilityFlags flags; if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) { return (flags & kSCNetworkReachabilityFlagsConnectionRequired); } return NO; } - (NetworkStatus)currentReachabilityStatus { NSAssert(_reachabilityRef != NULL, @"currentNetworkStatus called with NULL SCNetworkReachabilityRef"); NetworkStatus returnValue = NotReachable; SCNetworkReachabilityFlags flags; if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) { if (_alwaysReturnLocalWiFiStatus) { returnValue = [self localWiFiStatusForFlags:flags]; } else { returnValue = [self networkStatusForFlags:flags]; } } return returnValue; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Home/net/Reachability.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,762
```objective-c // // CustomModel.h // MVVMDemo // // Created by coderyi on 15/6/28. // #import <Foundation/Foundation.h> @interface YiCustomModel : NSObject @property (nonatomic,strong) NSString *title; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/Model/YiCustomModel.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
56
```objective-c // // CustomModel.m // MVVMDemo // // Created by coderyi on 15/6/28. // #import "YiCustomModel.h" @implementation YiCustomModel @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/Model/YiCustomModel.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
47
```objective-c // // TableViewController.m // YiRefresh // // Created by coderyi on 15/3/5. // #import "YiTableViewController.h" #import "YiRefreshHeader.h" #import "YiRefreshFooter.h" #import "YiTableViewModel.h" #import "YiTableViewDataSource.h" #import "YiTableViewDelegate.h" @interface YiTableViewController () { YiRefreshHeader *refreshHeader; YiRefreshFooter *refreshFooter; NSMutableArray *totalSource; YiTableViewModel *tableViewModel; UITableView *tableView; YiTableViewDataSource *tableViewDataSource; YiTableViewDelegate *tableViewDelegate; } @end @implementation YiTableViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if (iOS7) { self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight; } self.title=@"MVVMDemo With TableView"; self.view.backgroundColor=[UIColor whiteColor]; tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, YFScreen.width, YFScreen.height - 64) style:UITableViewStylePlain]; [self.view addSubview:tableView]; tableViewDataSource=[[YiTableViewDataSource alloc] init]; tableViewDelegate=[[YiTableViewDelegate alloc] init]; tableView.dataSource=tableViewDataSource; tableView.delegate=tableViewDelegate; tableViewModel=[[YiTableViewModel alloc] init]; totalSource=0; // YiRefreshHeader refreshHeader=[[YiRefreshHeader alloc] init]; refreshHeader.scrollView=tableView; [refreshHeader header]; __weak typeof(self) weakSelf = self; refreshHeader.beginRefreshingBlock=^(){ __strong typeof(self) strongSelf = weakSelf; [strongSelf headerRefreshAction]; }; // [refreshHeader beginRefreshing]; // YiRefreshFooter refreshFooter=[[YiRefreshFooter alloc] init]; refreshFooter.scrollView=tableView; [refreshFooter footer]; refreshFooter.beginRefreshingBlock=^(){ __strong typeof(self) strongSelf = weakSelf; [strongSelf footerRefreshAction]; }; } - (void)headerRefreshAction { [tableViewModel headerRefreshRequestWithCallback:^(NSArray *array){ totalSource=(NSMutableArray *)array; tableViewDataSource.array=totalSource; tableViewDelegate.array=totalSource; [refreshHeader endRefreshing]; [tableView reloadData]; }]; } - (void)footerRefreshAction { [tableViewModel footerRefreshRequestWithCallback:^(NSArray *array){ [totalSource addObjectsFromArray:array] ; tableViewDataSource.array=totalSource; tableViewDelegate.array=totalSource; [refreshFooter endRefreshing]; [tableView reloadData]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/Controller/YiTableViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
616
```objective-c // // TableViewController.h // YiRefresh // // Created by coderyi on 15/3/5. // #import <UIKit/UIKit.h> @interface YiTableViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/Controller/YiTableViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
45
```objective-c // // TableViewDataSource.m // MVVMDemo // // Created by coderyi on 15/6/28. // #import "YiTableViewDataSource.h" #import "YiCustomTableViewCell.h" #import "YiCustomModel.h" @implementation YiTableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _array.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { YiCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[YiCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; } cell.titleLabel.text = ((YiCustomModel *)[_array objectAtIndex:indexPath.row]).title; return cell; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/TableViewProtocol/YiTableViewDataSource.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
165
```objective-c // // TableViewDelegate.h // MVVMDemo // // Created by coderyi on 15/6/28. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface YiTableViewDelegate : NSObject<UITableViewDelegate> @property (nonatomic,strong) NSArray *array; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/TableViewProtocol/YiTableViewDelegate.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
65
```objective-c // // TableViewDelegate.m // MVVMDemo // // Created by coderyi on 15/6/28. // #import "YiTableViewDelegate.h" #import "YiCustomModel.h" @implementation YiTableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (_array.count>0) { UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:((YiCustomModel *)[_array objectAtIndex:indexPath.row]).title delegate:nil cancelButtonTitle:@"sure" otherButtonTitles:nil, nil]; [alert show]; } } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/TableViewProtocol/YiTableViewDelegate.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
124
```objective-c // // YiRefreshHeader.h // YiRefresh // // Created by apple on 15/3/6. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> typedef void (^BeginRefreshingBlock)(void); @interface YiRefreshHeader : NSObject @property UIScrollView *scrollView; @property (nonatomic, copy) BeginRefreshingBlock beginRefreshingBlock; -(void)header; -(void)endRefreshing; -(void)beginRefreshing; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/3rdLibs/YiRefresh/YiRefreshHeader.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
93
```objective-c // // YiRefreshFooter.h // YiRefresh // // Created by apple on 15/3/6. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> typedef void (^BeginRefreshingBlock)(void); @interface YiRefreshFooter : NSObject @property UIScrollView *scrollView; @property (nonatomic, copy) BeginRefreshingBlock beginRefreshingBlock; -(void)footer; -(void)endRefreshing; -(void)beginRefreshing; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/3rdLibs/YiRefresh/YiRefreshFooter.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
94
```objective-c // // TableViewDataSource.h // MVVMDemo // // Created by coderyi on 15/6/28. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface YiTableViewDataSource : NSObject<UITableViewDataSource> @property (nonatomic,strong) NSArray *array; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/TableViewProtocol/YiTableViewDataSource.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
65
```objective-c // // YiRefreshFooter.m // YiRefresh // // Created by apple on 15/3/6. // #import "YiRefreshFooter.h" @interface YiRefreshFooter (){ float contentHeight; float scrollFrameHeight; float footerHeight; float scrollWidth; BOOL isAdd; BOOL isRefresh; UIView *footerView; UIActivityIndicatorView *activityView; } @end @implementation YiRefreshFooter -(void)footer{ scrollWidth=_scrollView.frame.size.width; footerHeight=35; scrollFrameHeight=_scrollView.frame.size.height; isAdd=NO; isRefresh=NO; footerView=[[UIView alloc] init]; activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [_scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (![@"contentOffset" isEqualToString:keyPath]) return; contentHeight=_scrollView.contentSize.height; if (!isAdd) { isAdd=YES; footerView.frame=CGRectMake(0, contentHeight, scrollWidth, footerHeight); [_scrollView addSubview:footerView]; activityView.frame=CGRectMake((scrollWidth-footerHeight)/2, 0, footerHeight, footerHeight); [footerView addSubview:activityView]; } footerView.frame=CGRectMake(0, contentHeight, scrollWidth, footerHeight); activityView.frame=CGRectMake((scrollWidth-footerHeight)/2, 0, footerHeight, footerHeight); int currentPostion = _scrollView.contentOffset.y; // if ((currentPostion>(contentHeight-scrollFrameHeight))&&(contentHeight>scrollFrameHeight)) { [self beginRefreshing]; } } // -(void)beginRefreshing{ if (!isRefresh) { isRefresh=YES; [activityView startAnimating]; // _scrollView [UIView animateWithDuration:0.3 animations:^{ _scrollView.contentInset=UIEdgeInsetsMake(0, 0, footerHeight, 0); }]; // block _beginRefreshingBlock(); } } // -(void)endRefreshing{ isRefresh=NO; dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.3 animations:^{ [activityView stopAnimating]; _scrollView.contentInset=UIEdgeInsetsMake(0, 0, footerHeight, 0); footerView.frame=CGRectMake(0, contentHeight, YFScreen.width, footerHeight); }]; }); } -(void)dealloc{ [_scrollView removeObserver:self forKeyPath:@"contentOffset"]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/3rdLibs/YiRefresh/YiRefreshFooter.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
614
```objective-c // // OneTableViewCell.h // BigShow1949 // // Created by on 16/6/30. // #import <UIKit/UIKit.h> @interface OneTableViewCell : UITableViewCell @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/OneTableViewCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
44
```objective-c // // DataSource2.m // BigShow1949 // // Created by on 16/6/30. // #import "DataSource2.h" @implementation DataSource2 @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/DataSource2.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
42
```objective-c // // YiRefreshHeader.m // YiRefresh // // Created by apple on 15/3/6. // #import "YiRefreshHeader.h" @interface YiRefreshHeader (){ float lastPosition; float contentHeight; float headerHeight; BOOL isRefresh; UILabel *headerLabel; UIView *headerView; UIImageView *headerIV; UIActivityIndicatorView *activityView; } @end @implementation YiRefreshHeader -(void)header{ isRefresh=NO; lastPosition=0; headerHeight=35; float scrollWidth=_scrollView.frame.size.width; float imageWidth=13; float imageHeight=headerHeight; float labelWidth=130; float labelHeight=headerHeight; headerView=[[UIView alloc] initWithFrame:CGRectMake(0, -headerHeight-10, _scrollView.frame.size.width, headerHeight)]; [_scrollView addSubview:headerView]; headerLabel=[[UILabel alloc] initWithFrame:CGRectMake((scrollWidth-labelWidth)/2, 0, labelWidth, labelHeight)]; [headerView addSubview:headerLabel]; headerLabel.textAlignment=NSTextAlignmentCenter; headerLabel.text=@""; headerLabel.font=[UIFont systemFontOfSize:14]; headerIV=[[UIImageView alloc] initWithFrame:CGRectMake((scrollWidth-labelWidth)/2-imageWidth, 0, imageWidth, imageHeight)]; [headerView addSubview:headerIV]; headerIV.image=[UIImage imageNamed:@"down"]; activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; activityView.frame=CGRectMake((scrollWidth-labelWidth)/2-imageWidth, 0, imageWidth, imageHeight); [headerView addSubview:activityView]; activityView.hidden=YES; headerIV.hidden=NO; // _scrollViewKVOkeyPathcontentOffset [_scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; } // - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (![@"contentOffset" isEqualToString:keyPath]) return; // _scrollViewcontentSize contentHeight=_scrollView.contentSize.height; // , // _scrollView if (_scrollView.dragging) { NSLog(@"dragging == yes "); int currentPostion = _scrollView.contentOffset.y; NSLog(@"currentPostion = %zd", currentPostion); // if (!isRefresh) { [UIView animateWithDuration:0.3 animations:^{ // currentPostion if (currentPostion<-headerHeight*1.5) { headerLabel.text=@""; headerIV.transform = CGAffineTransformMakeRotation(M_PI); }else{ int currentPostion = _scrollView.contentOffset.y; // // ? if (currentPostion - lastPosition > 5) { lastPosition = currentPostion; headerIV.transform = CGAffineTransformMakeRotation(M_PI*2); headerLabel.text=@""; }else if (lastPosition - currentPostion > 5) { lastPosition = currentPostion; } } }]; } }else{ NSLog(@"dragging == NO ---------------"); // if ([headerLabel.text isEqualToString:@""]) { [self beginRefreshing]; } } } // -(void)beginRefreshing{ if (!isRefresh) { isRefresh=YES; headerLabel.text=@""; headerIV.hidden=YES; activityView.hidden=NO; [activityView startAnimating]; // _scrollView [UIView animateWithDuration:0.3 animations:^{ _scrollView.contentInset=UIEdgeInsetsMake(headerHeight*1.5, 0, 0, 0); }]; // block _beginRefreshingBlock(); } } // -(void)endRefreshing{ isRefresh=NO; dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.3 animations:^{ _scrollView.contentInset=UIEdgeInsetsMake(0, 0, 0, 0); headerIV.hidden=NO; headerIV.transform = CGAffineTransformMakeRotation(M_PI*2); [activityView stopAnimating]; activityView.hidden=YES; }]; }); } -(void)dealloc{ [_scrollView removeObserver:self forKeyPath:@"contentOffset"]; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVVM_coderyi/3rdLibs/YiRefresh/YiRefreshHeader.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
942
```objective-c // // DataSource1.h // BigShow1949 // // Created by on 16/6/30. // #import "MyBaseDataSource.h" @interface DataSource1 : MyBaseDataSource @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/DataSource1.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // DataSource1.m // BigShow1949 // // Created by on 16/6/30. // #import "DataSource1.h" @interface DataSource1 () @end @implementation DataSource1 //YFCellBackBlock - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; cell.backgroundColor = [UIColor lightGrayColor]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 200; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/DataSource1.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
124
```objective-c // // MyDataSourceViewController2.h // BigShow1949 // // Created by on 16/6/30. // #import <UIKit/UIKit.h> @interface MyDataSourceViewController2 : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/MyDataSourceViewController2.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
48
```objective-c // // ModelTwo.h // BigShow1949 // // Created by on 16/6/30. // #import <Foundation/Foundation.h> @interface ModelTwo : NSObject @property (nonatomic, strong) NSString *name; @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/ModelTwo.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
54
```objective-c // // MyDataSourceViewController.h // BigShow1949 // // Created by on 16/6/30. // #import <UIKit/UIKit.h> @interface MyDataSourceViewController : UIViewController /* , , */ @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/MyDataSourceViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // DataSource2.h // BigShow1949 // // Created by on 16/6/30. // #import "MyBaseDataSource.h" @interface DataSource2 : MyBaseDataSource @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/DataSource2.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // MyDataSourceViewController2.m // BigShow1949 // // Created by on 16/6/30. // #import "MyDataSourceViewController2.h" #import "DataSource2.h" #import "SecondTableViewCell.h" #import "ModelTwo.h" @interface MyDataSourceViewController2 () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) DataSource2 *datasource; @property (nonatomic, strong) NSMutableArray *dataArray; @end @implementation MyDataSourceViewController2 - (void)viewDidLoad { [super viewDidLoad]; // datasource [self configDataSource]; // tableview [self configTableView]; } - (void)configDataSource { // cell [self configData]; // cell // [self.tableView registerNib:[OneTableViewCell nib] forCellReuseIdentifier:NSStringFromClass([TCellOne class])]; [self.tableView registerClass:[SecondTableViewCell class] forCellReuseIdentifier:NSStringFromClass([SecondTableViewCell class])]; __weak __typeof(self) weakSelf = self; // cell YFCellSelectedBlock cellSelectedBlock = ^(id obj){ __strong __typeof(weakSelf) strongSelf = weakSelf; // cell [strongSelf cellSelectedWithObj:obj]; }; YFCellBackBlock cellBackBlock = ^(id cell , id data){ // DataSourcecellForRow SecondTableViewCell *cell2 = (SecondTableViewCell *)cell; cell2.backgroundColor = [UIColor blueColor]; }; // dataSource _datasource = [[DataSource2 alloc] initWithServerData:_dataArray andCellIdentifier:NSStringFromClass([SecondTableViewCell class])]; _datasource.cellSelectedBlock = cellSelectedBlock; _datasource.cellBackBlock = cellBackBlock; } - (void)configData { // _dataArray = [[NSMutableArray alloc] init]; // ModelTwo *one = [[ModelTwo alloc] init]; ModelTwo *two = [[ModelTwo alloc] init]; one.name = @""; two.name = @""; [_dataArray addObject:one]; [_dataArray addObject:two]; } - (void)configTableView { // _dataSource_tableview,_dataSource self.tableView.delegate = _datasource; self.tableView.dataSource = _datasource; self.tableView.tableFooterView = [UIView new]; } #pragma mark - #pragma mark - Action - (void)cellSelectedWithObj:(id)obj { NSLog(@"%@",obj); // MyDataSourceViewController2 *vc2 = [[MyDataSourceViewController2 alloc] init]; // [self.navigationController pushViewController:vc2 animated:YES]; } - (UITableView *)tableView { if (!_tableView) { UITableView *tableView = [[UITableView alloc] init]; tableView.frame = CGRectMake(0, 0, YFScreen.width, YFScreen.height); tableView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:tableView]; _tableView = tableView; } return _tableView; } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/MyDataSourceViewController2.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
636
```objective-c // // MyBaseDataSource.m // BigShow1949 // // Created by on 16/6/30. // #import "MyBaseDataSource.h" #import "UITableViewCell+YFDataSource.h" @interface MyBaseDataSource() @end @implementation MyBaseDataSource // - (id)initWithServerData:(NSArray *)serverData andCellIdentifier:(NSString *)identifier { self = [super init]; if(self) { self.serverData = serverData; // self.cellIdentifier = identifier; // } return self; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.serverData.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath]; // , cell.accessoryType = UITableViewCellAccessoryNone; cell.backgroundColor = [UIColor whiteColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; id data = self.serverData[indexPath.row]; [cell configCellWithEntity:data]; if (self.cellBackBlock) { self.cellBackBlock(cell,data); } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; self.cellSelectedBlock(indexPath); } @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/MyBaseDataSource.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
288
```objective-c // // ModelOne.m // BigShow1949 // // Created by on 16/6/30. // #import "ModelOne.h" @implementation ModelOne @end ```
/content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/ModelOne.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
42