Skip to content

Instantly share code, notes, and snippets.

View citynight's full-sized avatar
🎯
Focusing

Logan citynight

🎯
Focusing
View GitHub Profile
@citynight
citynight / Delegate.swift
Created April 2, 2018 12:05 — forked from onevcat/Delegate.swift
An auto-weak delegate for handle modern delegate pattern.
class Delegate<Input, Output> {
private var block: ((Input) -> Output?)?
func delegate<T: AnyObject>(on target: T, block: ((T, Input) -> Output)?) {
self.block = { [weak target] input in
guard let target = target else { return nil }
return block?(target, input)
}
}
func call(_ input: Input) -> Output? {