Mark Kang
Mark Kang

Reputation: 191

How to bind a property with changes found in any of multiple RACObserves

The following code works fine:

[RACObserve(self.person, firstName)
 subscribeNext:^(id x) {
     self.descriptionText = [self concatenateInformation];
 }];
[RACObserve(self.person, lastName)
 subscribeNext:^(id x) {
     self.descriptionText = [self concatenateInformation];
 }];
[RACObserve(self.person, primitiveIntegerAge)
 subscribeNext:^(id x) {
     self.descriptionText = [self concatenateInformation];
 }];

 - (NSString *)concatenateInformation {
     return [NSString stringWithFormat:@"%@ %@: %d", self.person.firstName, self.person.lastName, self.person.primitiveIntegerAge];
 }

Is there a way to allow any one of those RACObserve changes to just modify self.descriptionText using the RAC macro for binding it?

I have tried the following:

RAC(self, occupancySummaryText) =
[[RACSignal
  merge:@[
          RACObserve(self.person, firstName),
          RACObserve(self.person, lastName),
          RACObserve(self.person, primitiveIntegerAge) ]]
 map:^id(id value) {
     return [self concatenateInformation];
 }];

And while it works during application runtime, it will fail during an XCTest run with an error like this:

* Assertion failure in __36-[RACStream(Operations) flattenMap:]_block_invoke_2(), /Pods/ReactiveCocoa/ReactiveCocoaFramework/ReactiveCocoa/RACStream.m:75 * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Value returned from -flattenMap: is not a stream: name: '

How can I achieve the above in a more elegant way?

Upvotes: 2

Views: 496

Answers (1)

Mark Kang
Mark Kang

Reputation: 191

I found the cause of this problem, though I do not know the reason how it triggered this error.

In my Podfile, I have included ReactiveCocoa pod in both the application and test targets. Removing the ReactiveCocoa pod from the test target resolves the issue.

Original version having issues:

target 'Application' do
  pod 'ReactiveCocoa', '~> 2.3'
end

target 'ApplicationTests' do
  pod 'ReactiveCocoa', '~> 2.3'
end

Updated

target 'Application' do
  pod 'ReactiveCocoa', '~> 2.3'
end

target 'ApplicationTests' do

end

I would really appreciate if anyone could enlighten me on why this is so.

Hope this is useful to anyone else who face the same issue.

Upvotes: 1

Related Questions