Skip to content

Instantly share code, notes, and snippets.

View ha1f's full-sized avatar

はるふ ha1f

View GitHub Profile
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)
//
// WithPrevious.swift
//
// Created by ha1f on 2018/06/25.
// Copyright © 2018年 ha1f. All rights reserved.
//
import Foundation
import RxCocoa
import RxSwift
//
// 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.
//
// KeyboardSizeObserver.swift
// KeyboardFrameObserver
//
// Created by ha1f on 2019/02/08.
// Copyright © ha1f 2019年 ha1f. All rights reserved.
//
import UIKit
//
// UserDefaultsStoreItem.swift
//
// Created by ha1f on 2019/02/26.
// Copyright © 2019年 ha1f. All rights reserved.
//
import Foundation
struct UserDefaultsStoreItem<T> {
final class DeallocNotifier {
private var _observers: [() -> Void] = []
func observe(_ observer: @escaping () -> Void) {
_observers.append(observer)
}
deinit {
_observers.forEach { observer in
observer()
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 {
protocol Drinkable {
}
struct 🍶: Drinkable {}
struct 🍺: Drinkable {}
struct 🍸: Drinkable {}
struct Person {
}
//
// PhotoLibraryChangeObserver.swift
// ha1fAlbum
//
// Created by はるふ on 2018/10/29.
// Copyright © 2018年 はるふ. All rights reserved.
//
import Photos
import RxSwift
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()
}