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 / ViewModel+RealLifeExample.swift
Last active April 27, 2019 19:59
ViewModel+RealLifeExample
import RxSwift
import Action
enum SceneStateOutput {
case idle
case sendingNoRecipient
case sendingSomeRecipients(sendingList: [String: String])
case sending
}
@Herakleis
Herakleis / Singleton+AuthManager.swift
Created August 18, 2017 20:56
Singleton+Template
import RxSwift
import RxSwiftExt
enum AuthenticationStatus {
case none
case error(AuthServiceError)
case user(String)
}
final class AuthManager {
@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 / 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()
@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 / 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)
}