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
// | |
// CachableRequest.swift | |
// LIPS | |
// | |
import Foundation | |
import RxSwift | |
import RxCocoa | |
private extension ObservableType { |
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) | |
} | |
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
extension CGRect { | |
/// 線形補間した矩形を返す | |
/// - parameter rate: 変化割合。0 <= rate <= 1の範囲で指定する。 | |
func lerp(to rect: CGRect, rate: CGFloat) -> CGRect { | |
let lerp = _lerpCurried(rate) | |
return CGRect( | |
x: lerp(origin.x, rect.origin.x), | |
y: lerp(origin.y, rect.origin.y), | |
width: lerp(width, rect.width), | |
height: lerp(height, rect.height) |
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
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
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
// | |
// 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
// | |
// 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
// | |
// UIViewControllerReferenceCycleTests.swift | |
// TargetTests | |
// | |
import UIKit | |
import XCTest | |
@testable import Target |