Skip to content

Instantly share code, notes, and snippets.

View desugaring's full-sized avatar

Alex Semenikhine desugaring

  • Toronto, Canada
View GitHub Profile
@desugaring
desugaring / keypaths.playground
Created June 8, 2018 15:28
Two-way binding in iOS using KVO
//: Playground - noun: a place where people can play
import UIKit
/* Scroll to the bottom for examples */
typealias WritableObjectKeyPath<O: NSObject, V: Equatable> = (object: O, keyPath: WritableKeyPath<O, V>)
typealias ReadOnlyObjectKeyPath<O: NSObject, V: Equatable> = (object: O, keyPath: KeyPath<O, V>)
func bind<O: NSObject, O2: NSObject, V: Equatable>(source: ReadOnlyObjectKeyPath<O, V>, to target: WritableObjectKeyPath<O2, V>) -> NSKeyValueObservation?