2

I have a method that returns a Single:

func getEventStatus() throws -> Single<EventModel?> {
    return try mainService.getEventStatus()
}

And I tried to bind it to a tableView but got an error saying that it doesn't work on Singles, so I tried adding .asObservable() but now I get the error

Expression type 'Reactive<_>' is ambiguous without more context

I have tried to look up what it means but there doesn't seem to be any consistency to what the error means, or I can't seem to apply it to my case. This is what the bind looks like:

viewModel.getEventStatus().asObservable().bind(to: tableView.rx.items(cellIdentifier: EventLogTableViewCell.identifier, cellType: EventLogTableViewCell.self)) { row, data, cell in
    cell.viewModel = data
}.disposed(by:disposeBag)

As the method throws I added do { try catch{} } but that doesn't seem to make a difference.

What am I missing here?

Joakim Sjöstedt
  • 824
  • 2
  • 9
  • 18

1 Answers1

2

The problem is the signature of your method.

The getEventStatus() method only emits one EventModel and even that is an Optional.

The items(cellIdentifier:cellType:) method requires an Array of things.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • Thanks @Daniel, but how do I convert it to an array? I tried `try? viewModel.getEventStatus().asObservable().toArray().bind....` but then it says that "'PrimitiveSequence' has no member 'bind'" – Joakim Sjöstedt Jun 05 '20 at 12:53
  • Put brackets around EventModel and get rid of the question mark. – Daniel T. Jun 06 '20 at 02:36