Struggling to get a simple ReactiveCocoa 4 example working.
So it seems like a I want to create a signal from my gesture recogniser, map to extract the touch position relative to some view, then have my destination class observe this signal (or just have some final subscribeNext block that calls a method on my destination class).
However, can't seem to get anything working nor find a good example to follow.
I think I should be writing something like this (psuedo-code)
panRecognizer
.rac_gestureSignal()
.map { (pgr:UIPanGestureRecognizer) -> CGPoint in
return pgr.locationInView(self.someUiView)
}.subscribeNext { (location: CGPoint) -> Void in
self.someNetworkDelegate.updatePosition(location)
}
Is such a thing possible (it seems simple enough)? Am I perhaps trying to use the framework in a bad way?
With RAC4 this one should work well..
let gesRec = UIPanGestureRecognizer(target: self, action: "gesRecHandler:")
view.addGestureRecognizer(gesRec)
gesRec.rac_gestureSignal().toSignalProducer().map({ (x) -> CGPoint in
guard let pan = x as? UIPanGestureRecognizer else {return CGPointZero}
return pan.locationInView(self.view)
}).startWithNext { (pointInView) -> () in
print(pointInView)
}
In RAC4 there are some changes related to signals. So you need first of all convert your RACSignal to signal producer and start to observe it. You can read about signal producers in FrameworkOverview . Here is article about converting RACSignals to SignalProducer RACSignalToSignalProducer