A set of VIPER protocols for UIKit. To help you quicky implement VIPER pattern to your UIViewController.
File
> Swift Packages
> Add Package Dependency...
https://github.com/crystalwinghero/ViperUIKit.git
v1.1.0
Note: you can follow the examples for in Examples
folder.
Mapping object for all V-I-P-E-R classes/structs together as a whole.
import ViperUIKit
struct SampleViper : BaseViper {
typealias View = SampleViewController
typealias Interactor = SampleInteractor
typealias Presenter = SamplePresenter
typealias Entity = SampleEntity
typealias Router = SampleRouter
}
Add PresentableView
protocol on your ViewController.
import ViperUIKit
class SampleViewController : UIViewController, PresentableView {
//1. declare type
typealias Viper = SampleViper
//2. declare presenter
var presenter: Viper.Presenter!
override func viewDidLoad() {
super.viewDidLoad()
//3. call setup
presenter.setup()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//4. load content
presenter.loadContent()
}
}
Add BaseInteractor
on your Interactor.
import ViperUIKit
struct SampleInteractor : BaseInteractor {
typealias Input = Any
typealias Response = Any
func fetch(_ input : Input?, _ completion: @escaping (Response) -> Void) {
//TODO: add logic here
completion("Hello, world!")
}
}
Add BasePresenter
on your Presenter.
import ViperUIKit
///NOTE: mark as final class + inherits from NSObject
final class SamplePresenter : NSObject, BasePresenter {
//1. declare type
typealias Viper = SampleViper
//2. declare variables for your VIPER
//NOTE: always weak, to prevent retain cycle
weak var view : Viper.View!
var interactor: Viper.Interactor!
var router: Viper.Router!
var item : Viper.Entity?
var list : [Viper.Entity] = []
//3. default methods
func setup() {
//TODO: add your setup, i.e. navigation title, tableview data source, etc.
}
func loadContent() {
//TODO: fetch your data
interactor.fetch { (_) in
//TODO: refresh UI
}
}
func reloadContent() {
//TODO: add reload method
}
}
Add BaseEntity
on your Entity.
import ViperUIKit
struct SampleEntity : BaseEntity {
typealias PK = Int
var pk : PK { id }
var id : Int
}
Add BaseRouter
on your Router.
Note: default Router.create()
will call createWithNib()
by default, override it with createWithStoryboard()
, or implements it the way your viewController needed to otherwise.
import ViperUIKit
struct SampleRouter : BaseRouter {
typealias Viper = SampleViper
}
Create your VC through Router.create()
method.
//...
let vc = MyRouter.create() // VC will be created and linked with VIPER objects
self.navigationController?.pushViewController(vc, animated: true)
//...
link |
Stars: 0 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics