GithubHelp home page GithubHelp logo

viperit's Introduction

Viperit

Language Build Status Platform License Codecov codebeat badge CocoaPods Carthage Compatible Twitter

Write an iOS app following VIPER architecture. But in an easy way.

Viper the easy way

We all know Viper is cool. But we also know that it's hard to setup. This library intends to simplify all that boilerplate process. If you don't know yet what Viper is, check this out: Architecting iOS Apps with VIPER (objc.io)

Installation

Requirements

  • iOS 8.0+
  • Swift 4 (for Swift 3 compatibility download the v0.8.0)
  • Xcode 9

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

Specify Viperit into your project's Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Viperit'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

To integrate Viperit into your Xcode project using Carthage, specify it in your Cartfile:

github "ferranabello/Viperit"

Run carthage update to build the framework and drag the built Viperit.framework into your Xcode project.

Usage

0. Install the templates

Viperit Xcode templates can be found in the repository's /Templates/Viperit folder. To install them, open your terminal and run:

cd PATH/TO/REPO
mkdir -p ~/Library/Developer/Xcode/Templates/
cp -R Templates/Viperit ~/Library/Developer/Xcode/Templates/

Now, let's create our first Viperit module called "myFirstModule"!

1. Create a modules enum

You need at least one (you can use as many as you like, maybe to group modules by functionality) enum that implements the ViperitModule protocol to enumerate your application modules.

import Viperit

//MARK: - Application modules
enum AppModules: String, ViperitModule {
    case myFirstModule
}

2. Create the module

Let's use the provided Xcode template to easily create all the needed classes for the module. Just click New file in the document panel and select Protocol-oriented module or Object-oriented module under the "Viperit" section.

Module Creation

You can check "Also create a Storyboard file for module" if you want the storyboard file to be automatically created for you. Choose between "Universal" to use just one view for phones and tablets, and "Dedicated Tablet View" if you want to have a separated view for tablet devices.

3. Use storyboard, xib or programmatic views

Any Viperit module will assume its view is loaded from a Storyboard by default. But you can easily change this by overriding the variable viewType in your modules enum:

enum MySuperCoolModules: String, ViperitModule {
    case theStoryboardThing  
    case oldSchool
    case xibModule
    
    var viewType: ViperitViewType {
        switch self {
        case .theStoryboardThing: return .storyboard
        case .oldSchool: return .code
        case .xibModule: return .nib
        }
    }
}

4. Build the module and perform navigation

Imagine this is a new app and we want to load our "myFirstModule" module as the app's startup module

import Viperit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        let module = AppModules.myFirstModule.build()
        module.router.show(inWindow: window)
        return true
    }
}

This is just an example, you could of course use your own router functions instead of the provided show(inWindow:):

    window = UIWindow(frame: UIScreen.main.bounds)
    let module = AppModules.myFirstModule.build()
    let router = module.router as! MyFirstModuleRouter
    router.mySuperCoolShowFunction(inWindow: window)

5. Follow the Viper flow

Everything is ready for you to make great things the Viper way! Clone the repo and run the 'Example' target to see it in action! Or just try it with Cocoapods:

pod try Viperit

TODO

Extended documentation will be added soon

Author

Ferran Abelló

License

Viperit is released under MIT license and copyrighted by Ferran Abelló.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.