Created
September 19, 2014 17:21
-
-
Save justinmakaila/7e419e8f4333895a3b73 to your computer and use it in GitHub Desktop.
RAC Binding for Swift
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
// | |
// RAC.swift | |
// ReactiveCocoaExample | |
// | |
// Created by Justin Makaila on 7/23/14. | |
// Copyright (c) 2014 jmakaila. All rights reserved. | |
// | |
struct RAC { | |
var target: NSObject! | |
var keyPath: String! | |
var nilValue: AnyObject! | |
init(_ target: NSObject!, _ keyPath: String, nilValue: AnyObject? = nil) { | |
self.target = target | |
self.keyPath = keyPath | |
self.nilValue = nilValue | |
} | |
func assignSignal(signal: RACSignal) { | |
signal.setKeyPath(self.keyPath, onObject: self.target, nilValue: self.nilValue) | |
} | |
} | |
infix operator <~ {} | |
infix operator ~> {} | |
func <~ (rac: RAC, signal: RACSignal) { | |
rac.assignSignal(signal) | |
} | |
func ~> (signal: RACSignal, rac: RAC) { | |
rac.assignSignal(signal) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment