Skip to content

Instantly share code, notes, and snippets.

View alickbass's full-sized avatar

Oleksii Dykan alickbass

View GitHub Profile
@alickbass
alickbass / ApiResult.swift
Created June 20, 2017 18:25
Result enum that doesn't stop the stream
import RxSwift
protocol ApiResultType {
associatedtype ResultType
var result: ApiResult<ResultType> { get }
}
enum ApiResult<T>: ApiResultType {
typealias ResultType = T
case success(T)
@alickbass
alickbass / rxwithdiff.swift
Last active June 20, 2017 09:37
Rx with diffing components
import RxSwift
import ViewComponents
extension ObservableType where E: ComponentConvertible {
public func diff() -> Observable<Component<E.ComponentViewType>> {
return map({ $0.toComponent })
.scan((Component(), Component()), accumulator: { ($0.1, $1) })
.map({ $0.0.diffChanges(from: $0.1) })
}
}
import SwiftyJSON
extension Person {
enum PropertyKey: String {
case firstName, lastName, age, isMarried, height, hobbies
}
init(json: JSON) {
firstName = json[PropertyKey.firstName.rawValue].stringValue
lastName = json[PropertyKey.lastName.rawValue].stringValue