Skip to content

Instantly share code, notes, and snippets.

@iOSleep
iOSleep / namespace.swift
Last active May 7, 2019 04:39
namespace
public struct SomeTypeWrapper<Base> {
public
}
@iOSleep
iOSleep / Delegate.swift
Created May 7, 2019 03:26
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? {