Swiftpack.co - crystalwinghero/ViperUIKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Viper structure for UIKit
.package(url: "https://github.com/crystalwinghero/ViperUIKit.git", from: "1.1.1")


A set of VIPER protocols for UIKit. To help you quicky implement VIPER pattern to your UIViewController.


Swift Package Manager

  1. In Xcode, select File > Swift Packages > Add Package Dependency...
  2. Enter the URL for this repository https://github.com/crystalwinghero/ViperUIKit.git
  3. Choose a minimum semantic version of 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() {
        //3. call setup
    override func viewWillAppear(_ animated: Bool) {
        //4. load content


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)


Stars: 0
Last commit: 5 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics