A Viper Design framework for iOS
- Adds ViewControllers which bind the ViewController lifcycles to the interactor
- Has some commonly used presenter logic
- Has some commonly used router logic
Import ViperKit at the top of each swift file that uses the VIPER architecture.
import ViperKit
Extend ViperViewController
, ViperTableViewController
or ViperCollectionViewController
in your ViewController
class ViewController: ViperViewController {
}
Create your own presenter
class SomePresenter: ViperPresenter<ViewController> {
// Our ViewController extends ViperViewController which implements the
// ViperView protocol which is required by the presenter
}
Create your own router
class SomeRouter: ViperRouter<ViewController> {
func replace(_ viewController: UIViewController, options: UIViewAnimationOptions) {
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
// This assumes your appDelegate has the public method 'replace'
// Which is responsible for replacing the current view with another one
appDelegate.replace(viewController, options: options)
}
}
}
Create your own interactor
class SomeInteractor: ViperInteractor {
var presenter: SomePresenter
var router: SomeRouter
init(_ viewController: ViewController) {
presenter = SomePresenter(viewController)
router = SomeRouter(viewController)
}
}
Give your ViewController an interactor
let viewController = ViewController() // Or load from storyboard
viewController.interactor = ViperInteractor(viewController)
For more details and examples, this repository includes an Example Project.
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate ViperKit into your Xcode project using Carthage, specify it in your Cartfile
:
github "cuba/ViperKit"