Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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()
}