Skip to content

Instantly share code, notes, and snippets.

import RxSwift
import Action
protocol MyViewModelInputsType {
// Inputs headers
}
protocol MyViewModelOutputsType {
// Outputs headers
}
@Herakleis
Herakleis / Singleton+Template.swift
Created August 18, 2017 20:58
Singleton+Template
final class Singleton {
static let shared = Singleton()
private init() { }
}
@Herakleis
Herakleis / Scene.swift
Last active August 19, 2017 14:55
Scene+Template
import Foundation
enum Scene {
// Sub-group of scenes related to each other
// E.g.: all scenes part of a login process
case firstScene(FirstSceneViewModel)
case secondScene(SecondSceneViewModel)
// Another sub-group of scenes related to each other
@Herakleis
Herakleis / Scene+ViewControllerTemplate.swift
Last active August 19, 2017 15:16
Scene+ViewControllerTemplate
import UIKit
extension Scene {
func viewController() -> UIViewController {
switch self {
case .firstScene(let viewModel):
let nc = UINavigationController(rootViewController: FirstSceneViewController())
@Herakleis
Herakleis / BindableType.swift
Created August 19, 2017 15:28
BindableType
import UIKit
import RxSwift
protocol BindableType {
associatedtype ViewModelType
var viewModel: ViewModelType! { get set }
func bindViewModel()
}
@Herakleis
Herakleis / SceneCoordinatorType.swift
Created August 19, 2017 15:57
SceneCoordinatorType
import UIKit
import RxSwift
protocol SceneCoordinatorType {
init(window: UIWindow)
var currentViewController: UIViewController { get }
@discardableResult
func transition(to scene: Scene, type: SceneTransitionType) -> Observable<Void>
@Herakleis
Herakleis / SceneTransitionType.swift
Created August 19, 2017 16:15
SceneTransitionType
import UIKit
enum SceneTransitionType {
case root
case push(animated: Bool)
case modal(animated: Bool)
// Add custom transtion types...
case pushToVC(stackPath: [UIViewController], animated: Bool)
}
@Herakleis
Herakleis / AppDelegate+Coordinator.swift
Created August 19, 2017 16:46
AppDelegate+Coordinator
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
// Manually creates the window and makes it visible.
window = UIWindow(frame: UIScreen.main.bounds)
@Herakleis
Herakleis / SceneCoordinator+Action.swift
Created August 19, 2017 16:53
SceneCoordinator+Action
lazy var pushScene: CocoaAction = {
return Action { [weak self] in
guard let strongSelf = self else { return .empty() }
// The ViewModel is created and its dependencies are injected
let newSceneViewModel = NewSceneViewModel(service: NewSceneService(), coordinator: strongSelf.coordinator)
// A reference to the corresponding scene is created to be passed to the coordinator
let newScene = Scene.newScene(newSceneViewModel)
// The coordinator calls the specified transition function and returns an Observable<Void>
@Herakleis
Herakleis / ViewController+Template.swift
Last active August 19, 2017 16:59
ViewController+Template
import RxSwift
import RxCocoa
import Action
final class ViewController: UIViewController, BindableType {
// UI Elements
fileprivate var aButton = ViewController._aButton()
fileprivate var anotherButton = ViewController._aButton()
fileprivate let logo = ViewController._logo()