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 YearMonthDay { | |
var year: Int | |
var month: Int | |
var day: Int | |
/// Extracts yearMonthDay from Date, using calendar. | |
static func from(_ date: Date, calendar: Calendar = Calendar(identifier: .gregorian)) -> YearMonthDay { | |
let components = calendar.dateComponents([.year, .month, .day], from: date) |
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
// | |
// CircleView.swift | |
// | |
// Created by ha1f on 2019/02/27. | |
// Copyright © 2019年 ha1f. All rights reserved. | |
// | |
import UIKit | |
/// I guess this is faster than using cornerRadius. |
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
// | |
// KeyboardSizeObserver.swift | |
// KeyboardFrameObserver | |
// | |
// Created by ha1f on 2019/02/08. | |
// Copyright © ha1f 2019年 ha1f. All rights reserved. | |
// | |
import UIKit |
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
// | |
// UserDefaultsStoreItem.swift | |
// | |
// Created by ha1f on 2019/02/26. | |
// Copyright © 2019年 ha1f. All rights reserved. | |
// | |
import Foundation | |
struct UserDefaultsStoreItem<T> { |
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 DeallocNotifier { | |
private var _observers: [() -> Void] = [] | |
func observe(_ observer: @escaping () -> Void) { | |
_observers.append(observer) | |
} | |
deinit { | |
_observers.forEach { observer in | |
observer() |
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
protocol Drinkable { | |
} | |
struct 🍶: Drinkable {} | |
struct 🍺: Drinkable {} | |
struct 🍸: Drinkable {} | |
struct Person { | |
} |
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
class OperationGroup<T1, T2> { | |
private var item1: T1? | |
private var item2: T2? | |
private var observers: [(T1, T2) -> Void] = [] | |
func notify1(_ item: T1) { | |
item1 = item | |
_notifyIfNeeded() | |
} | |