Skip to content

Instantly share code, notes, and snippets.

@stigi
Created August 16, 2014 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigi/3678ed568d76cd2c5b24 to your computer and use it in GitHub Desktop.
Save stigi/3678ed568d76cd2c5b24 to your computer and use it in GitHub Desktop.
//
// RAC.swift
// ReactiveSwift
//
// Created by Yusef Napora on 6/10/14.
// Copyright (c) 2014 Yusef Napora. All rights reserved.
//
import Foundation
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)
}
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