Skip to content

Instantly share code, notes, and snippets.

@justinmakaila
Created September 19, 2014 17:21
Show Gist options
  • Save justinmakaila/7e419e8f4333895a3b73 to your computer and use it in GitHub Desktop.
Save justinmakaila/7e419e8f4333895a3b73 to your computer and use it in GitHub Desktop.
RAC Binding for Swift
//
// 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