Skip to content

Instantly share code, notes, and snippets.

interface Destination
object NoDestination : Destination
abstract class Screen(val name: String) {
abstract val parent: Screen
abstract val destination: Destination
open fun route(): String = listOfNotNull(
parent.route().takeIf { it.isNotBlank() },
name,
).joinToString("/")
@M-Miyazako
M-Miyazako / CellRemovable.swift
Created February 6, 2020 07:50
# 削除可能なテーブルセル 要RxSwift
import RxSwift
import UIKit
/// セルの削除が可能なプロトコル
protocol CellRemovable: class {
var cellRemovedSubject: PublishSubject<Int> { get }
func removeConfiguration(at indexPath: IndexPath) -> UISwipeActionsConfiguration?
}
extension CellRemovable {
@M-Miyazako
M-Miyazako / Instantiatable.swift
Created February 6, 2020 07:39
# Storyboardからインスタンスを生成する
import UIKit
/// Storyboardからインスタンスを生成可能なプロトコル
protocol Instantiatable: class {
/// Storyboardからインスタンスを生成する
static func instantiateFromStoryboard() -> Self
}
extension Instantiatable where Self: UIViewController {
@M-Miyazako
M-Miyazako / UIViewExt.swift
Created February 6, 2020 07:35
# Viewから親のViewControllerを取得する
extension UIView {
func parentViewController() -> UIViewController? {
var parent: UIResponder? = self
while let next = parent?.next {
if let viewController = next as? UIViewController {
return viewController
}
parent = next
}
return nil
@M-Miyazako
M-Miyazako / Indicator.swift
Last active February 6, 2020 07:24
# インジケータ 要RxSwift
import RxSwift
import UIKit
final class Indicator {
/// シングルトン
static let shared = Indicator()
/// モーダル用のView
private let modal = UIView()
@M-Miyazako
M-Miyazako / HogeDialog.swift
Created February 6, 2020 06:42
# ダイアログ 要RxSwift
import RxSwift
import UIKit
struct HogeDialog {
// MARK: - Completables
/// OKをタップしたイベントのストリーム
var ok: Observable<String> {
return okSubject.asObservable()
}
@M-Miyazako
M-Miyazako / DateTime.swift
Created February 6, 2020 06:29
# 日付関連
import Foundation
/// 日時
struct DateTime {
/// 値
let value: Date
/// DateTimeのインスタンスを生成する
///
/// - Parameter value: 日時の値
@M-Miyazako
M-Miyazako / DataSourceError.swift
Last active February 6, 2020 05:42
# Realmことはじめ 要Realm&RxSwift
import Foundation
/// データソースに関するエラー
enum DataSourceError: Error {
/// realmのエラー
case realmError(message: String)
/// キーチェーンのエラー
case keychainError(message: String)
}
@M-Miyazako
M-Miyazako / APIErrorResponse.swift
Created February 6, 2020 04:39
# ログインAPI 要APIKit&RxSwift
import Foundation
/// APIのエラー応答
struct APIErrorResponse: Decodable {
/// ステータス
let status: String
/// メッセージ(単体の場合)
let message: String?
/// メッセージ(複数の場合)
let messages: [String]?
@M-Miyazako
M-Miyazako / HeartRateResponse.swift
Created January 27, 2020 08:53
# Jsonデータをパースする {"DateTime":"2018-12-01 15:38:18","HeartRate":"66.454882"}
import Foundation
struct HeartRateResponse: Decodable {
let dateTime: DateTime
let heartRate: Double
enum CodingKeys: String, CodingKey {
case dateTime = "DateTime"
case heartRate = "HeartRate"
}