Upgrade to Pro — share decks privately, control downloads, hide ads and more …

VIPER - или то, о чем все говорят, но никто не рассказывает

Faf4a633b0d1e32a07a071039686c868?s=47 Egor Tolstoy
November 18, 2015

VIPER - или то, о чем все говорят, но никто не рассказывает

VIPER - это подход к архитектуре слоя presentation iOS-приложений (то есть всеми любимых Massive View Controller'ов), основанный на разбитии логики на несколько основных составляющих с едиными ответственностями: view, presenter, interactor и router.

Выступление охватывает следующие темы:
- Структура VIPER-модуля
- Связь модулей
- Возможности, открываемые использованием VIPER

Faf4a633b0d1e32a07a071039686c868?s=128

Egor Tolstoy

November 18, 2015
Tweet

Transcript

  1. VIPER то, о чем все говорят, но никто не рассказывает

  2. Автор Егор Толстой Ведущий iOS разработчик Rambler&Co Twitter: @igrekde www.github.com/igrekde

  3. CompositionViewController @interface

  4. @interface [self updateContactsView]; CompositionViewController

  5. - (void)saveMessageToDraft { // Crash } CompositionViewController

  6. - (void)sendMessage { // Crash } CompositionViewController

  7. @end - (void)updateAddressBook { // Crash // Crash // Crash

    } CompositionViewController
  8. - (void)updateAddressBook { if (invalidContacts) { return; } } @end

    CompositionViewController
  9. @interface CompositionViewController

  10. Хотим 100% crash-free! Хотим быстро и качественно! Хотим чистый код!

    Хотим модульность!
  11. None
  12. •Структура VIPER модуля •Связь модулей •Возможности использования VIPER

  13. None
  14. None
  15. None
  16. None
  17. VIEW PRESENTER INTERACTOR ROUTER E E

  18. VIEW PRESENTER INTERACTOR ROUTER E E

  19. VIEW PRESENTER INTERACTOR ROUTER E E

  20. VIEW PRESENTER INTERACTOR ROUTER E E

  21. VIEW PRESENTER INTERACTOR ROUTER E E

  22. VIEW PRESENTER INTERACTOR ROUTER E E

  23. VIEW PRESENTER INTERACTOR ROUTER E E

  24. VIEW PRESENTER INTERACTOR ROUTER E E TABLEVIEW CELLFACTORY

  25. View Presenter Interactor Router

  26. - (void)viewDidLoad { [super viewDidLoad]; } [self setupBarWithTitle:@"#mbltdev"]; - (void)setupBarWithTitle:(NSString

    *)title { self.navigationItem.title = title; } View Presenter Interactor Router
  27. [self setupBarWithTitle:@"#mbltdev"]; - (void)setupBarWithTitle:(NSString *)title { self.navigationItem.title = title; }

    View Presenter Interactor Router Lifecycle
  28. [self setupBarWithTitle:@"#mbltdev"]; View Presenter Interactor Router Lifecycle Navbar Setup

  29. View Presenter Interactor Router Lifecycle Navbar Setup Handles events

  30. View Presenter Interactor Router Lifecycle Navbar Setup Handles events BOOL

    valid = [self.inputValidator validatePhoneNumber:phoneNumber]; if (valid) { } else { } [self processToNextScreen]; [self showErrorAlertView];
  31. View Presenter Interactor Router Lifecycle Navbar Setup Handles events if

    (valid) { } else { } [self processToNextScreen]; [self showErrorAlertView]; Data validation
  32. View Presenter Interactor Router Lifecycle Navbar Setup Handles events if

    (valid) { } else { } [self showErrorAlertView]; Data validation [self processToNextScreen]; Module Routing
  33. View Presenter Interactor Router Lifecycle Navbar Setup Handles events if

    (valid) { } else { } Data validation Module Routing [self showErrorAlertView]; Shows data
  34. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else
  35. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else [rootSavingContext performBlock:^{ Message *message = [Message MR_findFirst]; }];
  36. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage
  37. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request]; [dataTask resume];
  38. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking
  39. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { segue.destinationViewController.inputData = @"inputData"; }
  40. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking Segues
  41. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = [tableView dequeueReusableCell]; [cell setupWithObject:cellObject]; } Segues
  42. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking Segues Table DataSource
  43. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking - (void)panGestureRecognizerDidChangeState:(id)sender { CGPoint panPoint = [sender translationInView:self.view]; self.view.frame = CGRectMake(panPoint.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height); } Segues Table DataSource
  44. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking Simple gestures Segues Table DataSource
  45. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking Simple gestures if (panPoint.x > 100.0f) { } [self showSideMenu]; Segues Table DataSource
  46. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking Simple gestures if (panPoint.x > 100.0f) { } [self showSideMenu]; Side Menu Segues Table DataSource
  47. View Presenter Interactor Router Lifecycle Navbar Setup Handles events Data

    validation Module Routing Shows data if-else Data storage Networking Segues Table DataSource Simple gestures Side Menu if (panPoint.x > 100.0f) { } Complex gestures
  48. VIEW PRESENTER INTERACTOR ROUTER E E

  49. VIEW PRESENTER INTERACTOR ROUTER E SERVICE SERVICE SERVICE E

  50. Роутер должен роутить

  51. VIEW PRESENTER INTERACTOR ROUTER E SERVICE SERVICE SERVICE E ASSEMBLY

  52. Экран = Модуль

  53. Экран = Модуль

  54. UIViewController UIView UITabBarController Daemon

  55. VIEW PRESENTER INTERACTOR ROUTER E SERVICE SERVICE SERVICE E ASSEMBLY

  56. VIEW PRESENTER INTERACTOR ROUTER E SERVICE SERVICE SERVICE E ASSEMBLY

  57. None
  58. None
  59. PRESENTER INTERACTOR VIEW ROUTER VIEW PRESENTER INTERACTOR ROUTER Модуль 1

    Модуль 2
  60. PRESENTER INTERACTOR VIEW ROUTER VIEW PRESENTER INTERACTOR ROUTER @"Module2Segue" <TransitionHandler>

    <ModuleInput> Модуль 1 Модуль 2
  61. @implementation Router [[self.transitionHandler openModuleUsingSegue:SegueIdentifier] thenChainUsingBlock:^void(id<SomeModuleInput> moduleInput) { [moduleInput moduleConfigurationMethod]; }];

    @end
  62. MODULEVIEW MODULEPRESENTER MODULEINTERACTOR MODULEROUTER <SUBMODULE2INPUT> <SUBMODULE1INPUT> <SUBMODULE3INPUT>

  63. None
  64. ~ 99% Code Coverage

  65. VIEW

  66. TEST

  67. pod 'MyApp/Core', '1.2.2' pod 'MyApp/Modules/CalendarModule', '1.5' pod 'MyApp/Modules/SettingsModule', '1.0.1' pod

    'SharedModules/Authorization', '2.3.4'
  68. None
  69. •VIPER увеличивает тестируемость приложения, •VIPER увеличивает модульность приложения, •VIPER делает

    нашу жизнь немного прекраснее.
  70. One more thing...

  71. ❤ VIPER

  72. Open Source •Рамблер.Конференции - приложение •Generamba - генератор •VIPER McFlurry

    - библиотека •The Book of VIPER - сборник статей https://github.com/rambler-ios
  73. Дизайн: студия «Рамблер Инфографика»