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
// | |
// PhotoLibraryChangeObserver.swift | |
// ha1fAlbum | |
// | |
// Created by はるふ on 2018/10/29. | |
// Copyright © 2018年 はるふ. All rights reserved. | |
// | |
import Photos | |
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
extension Reactive where Base: UIImagePickerController { | |
static func createAndPresent(from parent: UIViewController?, animated: Bool = true, configureImagePicker: @escaping (UIImagePickerController) throws -> Void = { x in }) -> Observable<[UIImagePickerController.InfoKey: Any]> { | |
return Observable.create { [weak parent] observer in | |
let imagePicker = UIImagePickerController() | |
let dismissDisposable = imagePicker.rx | |
.didCancel | |
.subscribe(onNext: { [weak imagePicker] _ in | |
guard let imagePicker = imagePicker else { | |
return | |
} |
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
/// JavaのStringBuilder的なインターフェースを想定 | |
final class URLBuilder { | |
private var components: URLComponents | |
init?(string: String) { | |
guard let components = URLComponents(string: string) else { | |
return nil | |
} | |
self.components = components | |
} |
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 | |
struct Parsed<Token> { | |
var token: Token | |
var remaining: String | |
init(_ token: Token, remaining: String) { | |
self.token = token | |
self.remaining = remaining | |
} |
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 RealmSwift | |
private extension Object { | |
/// 再帰的にDictionary型に変換する | |
func asDictionary() -> [String: Any] { | |
return objectSchema.properties | |
.reduce(into: [String: Any](), { (dictionary, property) in | |
let value = self[property.name] | |
dictionary[property.name] = _serializableValue(value) |
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 CGPoint { | |
func map(_ transform: (CGFloat) -> CGFloat) -> CGPoint { | |
CGPoint(x: transform(x), y: transform(y)) | |
} | |
} |
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 | |
import RxRelay | |
final class UpdatableArray<T>: ObservableType { | |
enum Action { | |
case replace([T]) | |
case append([T]) | |
case filter((T) -> Bool) |
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 Trie { | |
class Node { | |
var element: Element? | |
var children: [Path: Node] | |
init() { | |
self.element = nil | |
self.children = [:] | |
} |
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 | |
final class ThreadSafeCollection<T> { | |
private let _lock = NSRecursiveLock() | |
private var _observers: [Int: T] = [:] | |
private var _nextKey = 0 | |
func insert(_ observer: T) -> Int { | |
_lock.lock() | |
defer { |
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 | |
protocol Alphabet { | |
func accept(_ visitor: AlphabetVisitor) | |
} | |
class A { | |
let aProperty = "A" | |
} |