GoodRX is project / library created in GoodRequest. GoodRequest is a company from Zilina interested in mobile development, trends and improvment. In this repository we show how we are using reactivate programming in our iOS project based on MVVM pattern and some core libraries.
First of all we want to get rid of MVC- Massive view controller.
- Controller cointains too much logic
- Hard to use unit testing
- It's old concept
- logic is spread to more parts called Tasks or Managers
- a lot more testeable - you can test every part of code as separate part
- it's developed by Microsoft - don't know if it's good or bad
OBRAZOK
The main goal is separate the whole project to smaller parts.
-
Controller - Same like controller in MVC but without logic. Just showing data and changing UI
-
ViewModel - Core part of logic, every controller uses one ViewModel for yourself
-
Tasks, Managers - the logic about storage, network, core data or main parts of logic is spearated to those structures
-
Data models, structures - Why we choose structures over class? Caouse it's passed by values. We love values and don't like references.
The core libraries in our projects are:
RxSwift + RxCocoa
RxDataSources
This 3 libraries are easy to use but hard to master. Don't wory you got us and we will help you with every question you have, but if we don't you can add Slack channel. The community is great, especially in this slack channel where you obtain answer in 5 minutes.
First of all we have extensions for a lot of useful things in projects. Just use this project as pod and you will have access to all of our core extension
OBRAZOK
Is it same like ViewModel others MVVM concepts? NO
Call your file like: "pre Controller name"ViewModel
This file consists of 3 main parts:
- protocol for events
- Structure called View Model
- function called like Structure but with first latter lowerCased
Event is action connected with some user interaction. For example: When click on login button -> pass me Username and password. Basically we are using PublishSubject for this. The main difference in subjects is amount of cached values. More about this feature you can find in RxSwift + RxCocoa side.
protocol FoodMenuEvents {
var showFoodMenu : PublishSubject<FoodModelType> { get set }
var buyFood : PublishSubject<FoodModel> { get set }
var refresh : PublishSubject<()> { get set }
}
ShowFoodMenu - from UI we send type of meal - Enum(Drinks, ActualMenu, StaticMenu) buyFood - it emit value when buy button is clicked refresh - emits when user uses pull to refresh