Skip to content

Instantly share code, notes, and snippets.

View ConnectionObserver.swift
import Network
protocol ConnectionAttribute: Equatable {
init(path: NWPath)
}
class ConnectionObserver<T: ConnectionAttribute> {
var handler: ((T) -> Void)?
private var monitor: NWPathMonitor
View DeinitObserver.swift
final class DeinitObserver {
private let key: String
private weak var target: AnyObject?
private let deinitHandler: () -> Void
deinit {
deinitHandler()
}
init(for target: AnyObject, deinitHandler: @escaping () -> Void) {
View MulticastDelegate.swift
class WeakObject<T: AnyObject>: Hashable {
private(set) weak var object: T?
let identifier: ObjectIdentifier
static func == (lhs: WeakObject<T>, rhs: WeakObject<T>) -> Bool {
return lhs.identifier == rhs.identifier
}
func hash(into hasher: inout Hasher) {
hasher.combine(identifier)
@TaLinh
TaLinh / Decode_Dynamic_Key.swift
Last active Jul 30, 2021
Decode JSON with dynamic key
View Decode_Dynamic_Key.swift
import Foundation
let clientJSON = """
{
"clients": [
{
"name": "John",
"amount": 1000
},
{