Created
May 1, 2015 03:30
-
-
Save jckarter/b181a1d46e2ae043d7db to your computer and use it in GitHub Desktop.
Capture property getter/setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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