Created
August 16, 2014 22:19
-
-
Save stigi/3678ed568d76cd2c5b24 to your computer and use it in GitHub Desktop.
By http://napora.org/a-swift-reaction/ & http://www.scottlogic.com/blog/2014/07/24/mvvm-reactivecocoa-swift.html
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
// | |
// 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