Created
April 27, 2015 02:55
-
-
Save ruandao/dca40ace8ae1436a2c5b to your computer and use it in GitHub Desktop.
rac bridge
This file contains hidden or 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
| import Foundation | |
| public struct RAC { | |
| var target: NSObject | |
| var keyPath: String | |
| var nilValue: AnyObject? | |
| public init(_ target: NSObject, _ keyPath: String, nilValue: AnyObject? = nil) { | |
| self.target = target | |
| self.keyPath = keyPath | |
| self.nilValue = nilValue | |
| } | |
| func assignSignal(signal : RACSignal) -> RACDisposable { | |
| return signal.setKeyPath(self.keyPath, onObject: self.target, nilValue: self.nilValue) | |
| } | |
| } | |
| infix operator <~ { | |
| associativity right | |
| precedence 90 | |
| } | |
| public func <~ (rac: RAC, signal: RACSignal) -> RACDisposable { | |
| return signal ~> rac | |
| } | |
| public func ~> (signal: RACSignal, rac: RAC) -> RACDisposable { | |
| return rac.assignSignal(signal) | |
| } | |
| public func RACObserve(target: NSObject!, keyPath: String) -> RACSignal { | |
| return target.rac_valuesForKeyPath(keyPath, observer: target) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment