Skip to content

Instantly share code, notes, and snippets.

@jckarter
Created May 1, 2015 03:30
Show Gist options
  • Save jckarter/b181a1d46e2ae043d7db to your computer and use it in GitHub Desktop.
Save jckarter/b181a1d46e2ae043d7db to your computer and use it in GitHub Desktop.
Capture property getter/setter
public class Property<T> {
let getter: () -> T
let setter: T -> ()
public init(_ getter: () -> T, _ setter: T -> ()) {
self.getter = getter
self.setter = setter
}
public var value: T {
get { return getter() }
set { setter(newValue) }
}
}
var x = 0
let property = Property({ x }, { x = $0 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment