This file contains hidden or 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 CopyableLabel: UILabel { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
_commonInit() | |
} | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
private func _jsonSerialization(from encodable: Encodable) throws -> String { | |
let jsonEncoder = JSONEncoder() | |
jsonEncoder.outputFormatting = .prettyPrinted | |
let encodedData = try jsonEncoder.encode(config) | |
return String(data: encodedData, encoding: .utf8)! | |
} | |
func prettyPrint(_ encodable: Encodable) { | |
do { | |
print(try _jsonSerialization(from: encodable)) |
This file contains hidden or 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
// swiftlint:disable all | |
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen | |
{% if catalogs %} | |
{% set imageAlias %}{{param.imageAliasName|default:"AssetImageTypeAlias"}}{% endset %} | |
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %} | |
#if os(OSX) | |
import AppKit.NSImage | |
{{accessModifier}} typealias {{imageAlias}} = NSImage | |
#elseif os(iOS) || os(tvOS) || os(watchOS) |