Swift ReactiveCocoa combinationLatest
in obj-c, I can use this method:
RACSignal *signUpActiveSignal = [RACSignal combineLatest:@[validUsernameSignal, validPasswordSignal]
reduce:^id(NSNumber*usernameValid, NSNumber *passwordValid){
return @([usernameValid boolValue]&&[passwordValid boolValue]);
}];
when i convert it to swift like:
RACSignal.combineLatest([accountSignal, passwordSignal]) { () -> AnyObject! in
// arguments
return true
}.subscribeNext { (reduceResult: AnyObject!) -> Void in
KMLog("\(reduceResult)")
}
how can i get the parameters
+3
source to share
1 answer
I have not been able to figure out how to use this closure for combineLatest
, but you can use map
. The entrance is an object RACTuple
. You can get objects from input signals like this:
RACSignal.combineLatest([accountSignal, passwordSignal]).map {
let tuple = $0 as! RACTuple
let account = tuple.first as! String
let password = tuple.second as! String
// your code here
}
Obviously, you want your objects to be bound to their actual types, but I just used Strings here as an example. And remember that you will have to return the merged object at the end of the closure map
.
+6
source to share