Closed bangedorrunt closed 11 years ago
The rac_save
method returns a signal that will only complete
or error
since it uses the PFRACBooleanCallback
. [PFObject save]
either succeeds or fails - there's no "value" that makes sense to send across the signal.
Thanks @mhupman for your confirmation, as I looked at PFObject+RacExtensions.h
header file, it said
/// Saves the PFObject. /// /// @see -saveInBackgroundWithBlock: /// /// @return A signal that completes on successful save.
So I did expect a returned BOOL flag
. In this case how would I catch the error signal
? Because I want to have an alert view
that show warning message when saving PFObject
to Parse
unsuccessfully
You won't get a BOOL result back explicitly, but it will be implied by the signal's behavior. If your signal gets a completed event, you can assume the save was successful (success == YES
). However, if your signal gets an error event, the save was unsuccessful (success == NO
) and the error
parameter will contain details of the failure.
Use subscribeError:completed:
if you want to observe both success and failure of the rac_save
and get access to the underlying Parse error.
Tks @mhupman, I got my issue sorted out by using subscribeError:completed:
, my last question is there are possibilities that I would merge some rac_save signals
, what kind of value rac_save
would return? or I just simple declare ^ (id x)
for each returned signal value?
If I understand your question correctly, you want to know when 2 or more rac_save
s finish or error. You can use [RACSignal merge:]
to accomplish that. Example:
RACSignal *save1 = [pfObject1 rac_save];
RACSignal *save2 = [pfObject2 rac_save];
[[RACSignal merge:@[save1, save2]] subscribeError:^(NSError *error){
// One of the saves encountered an error
} completed^{
// Both objects saved successfully
}];
How about
RACSignal *save1 = [pfObject1 rac_save];
RACSignal *save2 = [pfObject2 rac_save];
[[[RacSignal zip:@[save1, save2]] reduce:^(id x, id y) {
// Do stuff here
}] flatten] subscribeCompleted:^ {
// Do other stuff here
}];
What's your though of data type x
and y
???
Edited: For correct example
As I stated above, the signal returned by rac_save
will never send any values (by design). subscribeNext:
, map:
, flattenMap:
and their ilk aren't of any use here since they only really make sense if we expect the signals in question to send values along. In this case, [RACSignal merge:]
just aggregates the error and completed events of the signals passed into it, it won't inject any values into the stream.
If you explained what you are trying to do I could try to provide more accurate guidance.
Really appreciate your caring and quick response :+1: . I totally understand now. It's just because I'm learning both ReactiveCocoa
& Parse-RacExtensions
, so there is a gap between them that I need to understand to catch up :-) Again, thank you heaps @mhupman :star:
@mhupman :ok_hand:
@babygau If the circumstances dictate, and you need -rac_save
to return a value for further operation composition, you can use -concat:
.
For example:
[[object rac_save] concat:[RACSignal return:@YES]];
// or
[[object rac_save] concat:[RACSignal return:@object]];
This applies to any complete-or-error signal.
Hi @kastiglione, I'm trying to save an
PFObject
after modify its data. But some howrac_save
is not fired when I subscribe to that signal:Updated:
subscribeCompleted
is working in my case