Skip to content

Instantly share code, notes, and snippets.

View soxjke's full-sized avatar

Petro Korienev soxjke

View GitHub Profile
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 November 1, 2017 14:02
Test-aware app launch
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
@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
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()
import Foundation
public struct AppError: Swift.Error {
public enum AppErrorReason {
public enum API: String {
case wrong_password
case invalid_email
}
public enum Validation: String {
case invalid_phone_number
import Foundation
enum AppEvent {
case locationPermissionResult(success: Bool)
case locationRequest
case locationResult(latitude: Double, longitude: Double, timestamp: TimeInterval, error: Error?)
case geopositionRequest
case geopositionResult(geoposition: Geoposition, error: Error?)
case weatherRequest
case weatherResult(current: Weather, forecast: [Weather], error: Error?)
import Foundation
enum LocationState {
case notYetRequested
case notAvailable
case available
}
enum LocationRequestState {
case none
import Foundation
import Redux_ReactiveSwift
extension AppState: Defaultable {
static var defaultValue: AppState = AppState(location: AppLocation(locationState: .notYetRequested,
locationRequestState: .none),
weather: AppWeather(geopositionRequestState: .none,
weatherRequestState: .none))
}
import Foundation
import CoreLocation
import ReactiveSwift
class LocationService: NSObject {
static let shared: LocationService = LocationService()
fileprivate lazy var locationManager: CLLocationManager = self.setupLocationManager()
fileprivate let appStore: AppStore = AppStore.shared
private override init() {
import Foundation
import Quick
import Nimble
@testable import Simple_Weather_App
class GeopositionSpec: QuickSpec {
override func spec() {
let geopositionJSON: [String: Any] = try! JSONSerialization.jsonObject(with: try! Data.init(contentsOf: Bundle.test.url(forResource: "Geoposition", withExtension: "json")!)) as! [String: Any]
describe("parsing") {
let geoposition = try? Geoposition(JSON: geopositionJSON)