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
// | |
// UIViewControllerReferenceCycleTests.swift | |
// TargetTests | |
// | |
import UIKit | |
import XCTest | |
@testable import Target |
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
// | |
// Comparable+Clamp.swift | |
// | |
import Foundation | |
extension Comparable { | |
/// minとmaxの範囲に収める | |
func clamp(min minValue: Self, max maxValue: Self) -> Self { | |
return max(min(self, maxValue), minValue) |
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
// | |
// WithPrevious.swift | |
// | |
// Created by ha1f on 2018/06/25. | |
// Copyright © 2018年 ha1f. All rights reserved. | |
// | |
import Foundation | |
import RxCocoa | |
import RxSwift |
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
// | |
// WithBlockingView.swift | |
// | |
extension ObservableConvertibleType { | |
/// actionがcompleteするまで画面を表示する | |
func withBlockingView(from parentViewController: UIViewController) -> Observable<Element> { | |
let viewController = _BlockingLoadingViewController(self) | |
return viewController.result | |
.do(onSubscribed: { [weak parentViewController] in |
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
func const<T, U>(_ value: T) -> (U) -> T { | |
return { _ in value } | |
} | |
func identity<T>() -> (T) -> T { | |
return { $0 } | |
} |
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 | |
protocol WoExecutable { | |
func を<Result>(_ process: WoProcess<Self, Result>) -> Result | |
} | |
extension WoExecutable { | |
func を<Result>(_ process: WoProcess<Self, Result>) -> Result { | |
return process.process(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
final class CircleImageRenderer { | |
let image: Observable<UIImage> | |
init(radius: CGFloat, fillColor: UIColor = .white) { | |
self.image = Observable.create { observer in | |
let format = UIGraphicsImageRendererFormat.default() | |
format.scale = UIScreen.main.scale | |
let width = radius * 2 | |
let size = CGSize.square(width) | |
let renderer = UIGraphicsImageRenderer( |
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
/// delegateなどを配列などに持ちたいときに使う | |
private final class WeakObject<T: AnyObject> { | |
weak var object: T? | |
init(_ object: T?) { | |
self.object = object | |
} | |
} | |
final class PageViewControllerDelegateMulticaster: NSObject, UIPageViewControllerDelegate { |
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
/// リクエストをして、データをキャッシュする | |
/// ロード中mの再呼び出しは無視する | |
/// これだと、一回データ取得して、二回目でエラー、みたいなときにつらい | |
class Repository<T> { | |
typealias State = RepositoryState<T, Error> | |
private let _request: Observable<T> | |
let state = BehaviorRelay<State>(value: .possible) | |
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
final class LazyBehaviorRelay<Element>: ObservableType, ObserverType { | |
private let _behaviorRelay = BehaviorRelay<Element?>(value: nil) | |
private let _emittedValue: Observable<Element> | |
init() { | |
_emittedValue = _behaviorRelay | |
.filterNil() | |
.share(replay: 1, scope: .forever) | |
} | |