Skip to content

Instantly share code, notes, and snippets.

import UIKit
protocol Transitionable: class {
weak var navigationCoordinator: CoordinatorType? { get }
}
protocol CoordinatorType: class {
var baseController: UIViewController { get }
protocol RepositoryViewModelType: Transitionable //Make our view model Transitionable {
var repositorySubject: PublishSubject<Repository> { get }
func fetchRepositories(for observableText: Observable<String>) -> Driver<Result<[Repository]>>
}
class RepositoryViewModel : RepositoryViewModelType {
fileprivate let disposeBag = DisposeBag()
fileprivate func setup() {
... older code
//biand a repository to the view model when the user selects a row
tableView
.rx
.modelSelected(Repository.self)
.bindTo(viewModel.repositorySubject)
.addDisposableTo(disposeBag)
import Foundation
import RxCocoa
import RxSwift
import RxAlamofire
import Alamofire
import ObjectMapper
enum CommonError : Error {
case parsingError
import Foundation
import RxCocoa
import RxSwift
import Alamofire
//this protocol represents a repository view model then anyone can implement this and perform the fetch.
protocol RepositoryViewModelType {
func fetchRepositories(for observableText: Observable<String>) -> Driver<Result<[Repository]>>
}
import UIKit
import RxCocoa
import RxSwift
class MainViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
fileprivate let disposeBag = DisposeBag()
import Foundation
protocol ValueRepresentable: RawRepresentable {
func value() -> String
}
extension ValueRepresentable {
func namespaced<T: RawRepresentable>(_ key: T) -> String {
@gorozco58
gorozco58 / Swift generic numbers operations.swift
Last active November 2, 2016 19:57
This is an easy way to apply operation to generic numbers (Int, Float, Double, etc.)
protocol Math {
static func +(lhs: Self, rhs: Self) -> Self
static func *(lhs: Self, rhs: Self) -> Self
init()
}
//Extend all numbers you want to
extension Int : Math {}
extension Double : Math {}