This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
indirect enum Tree<Element : Comparable> { | |
case Empty | |
case Node(Element, Tree<Element>, Tree<Element>) | |
init() { | |
self = .Empty | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxSwift | |
extension ObservableType where E == Bool { | |
func negate() -> Observable<Bool> { | |
return map(!) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Neat way of avoiding if lets/guard lets | |
extension Optional { | |
func then(_ handler:(Wrapped) -> Void) { | |
switch self { | |
case .some(let value): handler(value) | |
case .none: break | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ViewModelType { | |
associatedtype Model | |
associatedtype Input | |
init(model: Model, input: Input) | |
} | |
class ViewModel: ViewModelType { | |
required init(model: Model, input: Input) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ViewModelType { | |
associatedtype Model | |
associatedtype Input | |
init(model: Model, input: Input) | |
} | |
class ViewModel: ViewModelType { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import Moya | |
import Unbox | |
public extension ObservableType where E == Response { | |
public func mapObject<T: Unboxable>(type: T.Type) -> Observable<T> { | |
return flatMap { response -> Observable<T> in | |
return Observable.just(try response.mapObject(type: T.self)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class PixelWidthConstraint: NSLayoutConstraint { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
constant = 1.0 / UIScreen.main.scale | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdjustableVisualEffectView: UIVisualEffectView { | |
private var animator: UIViewPropertyAnimator! | |
init(effect: UIVisualEffect?, intensity: CGFloat) { | |
super.init(effect: nil) | |
self.animator = UIViewPropertyAnimator(duration: 1, curve: .linear) { [weak self] in | |
self?.effect = effect | |
} | |
self.intensity = intensity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Combine | |
protocol DiffableListDataSourceType { | |
associatedtype SectionIdentifier: Hashable | |
associatedtype ItemIdentifier: Hashable | |
func apply(_ snapshot: NSDiffableDataSourceSnapshot<SectionIdentifier, ItemIdentifier>, | |
animatingDifferences: Bool, | |
completion: (() -> Void)?) |
OlderNewer