-1

Suppose I have an var id = Variable<Int>(0). I want to observe changes to it from another Variable or Observable called team (var team = Observable<Team>). the team observable will be observed by the view controller and will update the UI there. Therefore, the id variable serves only to create/update (through creating Team(id: id) ) the value of the team observable.

I have been trying multiple approaches such as combineLatest or subscribe but I always get compile error saying:

Closure cannot implicitly capture a mutating self parameter

What's going on?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
rgoncalv
  • 5,825
  • 6
  • 34
  • 61
  • Can you try and further explain what you're trying to do here? The question is a bit unclear. Also some code of what you have tried would be great :) – Shai Mishali Dec 19 '17 at 10:08
  • [rgoncalv](https://stackoverflow.com/users/6096029/rgoncalv) did either of the answers posted below solve the problem for you? – RLoniello Dec 19 '17 at 20:10

1 Answers1

1

Your instance of Team(id:) is most likely a struct which are passed by value (Value Type) not by reference (Reference Type), therefore it cannot capture self while off of the main thread. See "Classes and Structures" in the swift programming guide

Change your Structure to a Class and it should work as expected: Simple observable struct with RxSwift?

RLoniello
  • 2,309
  • 2
  • 19
  • 26