Skip to content

Instantly share code, notes, and snippets.

Petro Korienev soxjke

Block or report user

Report or block soxjke

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ViewModel.swift
enum UIState {
case current
case forecast(page: Int)
}
enum UIEvent {
case turnCurrent
case turnForecast
case turnLeft
case turnRight
View ViewController.swift
func setupObserving() {
currentWeatherView.reactive.weatherFeatures <~ viewModel.weatherFeatures
loadingIndicator.reactive.isAnimating <~ viewModel.isLoading
segmentedControl.reactive.isEnabled <~ viewModel.isEnabledControl(for: Set([.turnCurrent, .turnForecast]))
reactive.title <~ viewModel.title
reactive.rightBarButtonItem <~ viewModel.isLoading.map { [weak self] (isLoading) -> UIBarButtonItem? in
return isLoading ? self?.loadingBarButtonItem : self?.refreshBarButtonItem
}
@soxjke
soxjke / right
Last active Feb 15, 2018
comma-separated
View right
255, 1, 1, 1, 0
2233, 0, 1, 1, 1
@soxjke
soxjke / right
Last active Feb 15, 2018
No headline
View right
255, 1, 1, 1, 0
2233, 0, 1, 1, 1
View ComplexWay.swift
import UIKit
public protocol NibInstantiator {
associatedtype Base
func instantiate() -> Base
}
public extension NibInstantiator where Base: UIView {
public func instantiate() -> Base {
guard let view =
View AuthManager.swift
enum AuthError: Error {
case wrongAuthData,
case wrongDeauthData
}
class AuthManager {
let networkManager: // injected dependency
func deauthenticateUser(user: User) -> SignalProducer<User, AuthError> {
// perhaps go to network:
return SignalProducer { (observer, disposable) in
View UploadServiceImpl.swift
enum TestError: Swift.Error {
case uploadFailed
}
class Album {
let pages: [Page] = []
}
class Page {}
class UploadServiceImpl {
private(set) lazy var addAction = Action<Album, Void, TestError>(execute:self.addActionBlock)
private lazy var pageAction = Action<Page, Void, TestError>(execute:self.pageActionBlock)
@soxjke
soxjke / AppDelegate.swift
Created Nov 1, 2017
Test-aware app launch
View AppDelegate.swift
import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let _ = AppStore.shared
let _ = LocationService.shared
let _ = WeatherService.shared
View AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let _ = AppStore.shared
let _ = LocationService.shared
let _ = WeatherService.shared
View WeatherService.swift
class WeatherService {
private struct Constants {
static let apiKey = "z74X7aKpZlip02a5Wlrq9R70JkDnOZsq"
}
static let shared: WeatherService = WeatherService()
fileprivate lazy var sessionManager: SessionManager = self.setupSessionManager()
fileprivate let appStore: AppStore = AppStore.shared
private init() {
setupObserving()
You can’t perform that action at this time.