Skip to content

Instantly share code, notes, and snippets.

@Herakleis
Herakleis / Coordinator+popped.swift
Last active September 14, 2017 17:15
Coordinator popped func
import RxSwift
@discardableResult
func popped(to viewController: UIViewController) -> Observable<Void> {
currentViewController = viewController
return .empty()
}
@Herakleis
Herakleis / ServiceType2+FriendRequests.swift
Created August 20, 2017 10:05
ServiceType2+FriendRequests
import RxSwift
protocol UsersBaseServiceType {
func observeCurrentFriendRequests() -> Observable<YourDatabaseResultType>
}
final class UsersBaseService {
static let shared = UsersBaseService()
@Herakleis
Herakleis / ServiceType1+FriendRequests.swift
Last active August 20, 2017 09:51
ServiceType1+FriendRequests
import RxSwift
protocol MyViewModelServiceType {
func observeCurrentNumberOfFriendRequests() -> Observable<Int>
}
struct MyViewModelService: MyViewModelServiceType {
private let usersBaseService = UsersBaseService.shared
@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 / 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.swift
Created August 19, 2017 16:31
SceneCoordinator
import UIKit
import RxSwift
import RxCocoa
final class SceneCoordinator: SceneCoordinatorType {
fileprivate var window: UIWindow
var currentViewController: UIViewController
required init(window: UIWindow) {
@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 / 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 / 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 / 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())