I inherited a somewhat old project written in ReactiveSwift (v3.1.0) and ReactiveCocoa (v7.2.0). When I opened it on Xcode 10.1, it was built without an issue. But when I did the same on Xcode 10.3, I get the error Ambiguous use of operator '<~' on the following block of code.
self.newMatchesTitleLabel.reactive.text <~ self.viewModel.newMatchesViewModel.data.producer.map { matches in
let newMatchesCount = matches.filter({ !$0.hasViewedOnce }).count
let newMatchesString = matches.count == 1 ? "New Match" : "New Matches"
return newMatchesCount == 0 ? newMatchesString : "\(newMatchesString) (\(newMatchesCount))"
}
It seems to be because of all the variables and calculations done inside the closure, the compiler somehow fails to infer the type(?). When I comment out those parts, compiler shuts up. But obviously I need these to work. Is there a way to fix this just the way it is?
I attempted taking out those parts out of the closure by declaring two class level variables.
self.newMatchesCount <~ self.viewModel.newMatchesViewModel.data.producer.map { $0.filter({ !$0.hasViewedOnce }).count }
self.newMatchesString <~ self.viewModel.newMatchesViewModel.data.producer.map { $0.count == 1 ? "New Match" : "New Matches" }
What I can't figure out now is how to the final boolean check and assign that value to the newMatchesTitleLabel
the reactive way.
I'm not well-versed in ReactiveSwift/ReactiveCocoa so I might be making it worse. And updating the entire project to use the latest versions is out of the question at this point unfortunately. I just need this error to go away.