-1

Swift's Combine's CurrentValueSubject offers 2 ways to change the underlying value:

  1. subject.value = newValue
  2. subject.send(newValue)

Is there anything fundamentally different in these 2 lines? I think I notice the inconsistencies sometimes in terms of: on which run loop does the value get changed? when do subscribers receive the values? etc

But I cannot find any documentation on that so I was wondering if anyone could explain the actual difference here. Thank you!

ramzesenok
  • 5,469
  • 4
  • 30
  • 41
  • 3
    "But I cannot find any documentation on that" What about the part of the documentation that says, flat out, "Calling `send(_:)` on a CurrentValueSubject also updates the current value, making it equivalent to updating the value directly"??? "Equivalent". That means they do the same thing. – matt Aug 04 '23 at 12:46
  • @matt right, yet I see e.g. my tests behave differently when I use one versus the other. That’s what the question is about, is there anything behind it apart the fact that both versions change the underlying value? Also: why do we even have `send` if we could just use `.value =`? – ramzesenok Aug 04 '23 at 19:17
  • Also @matt have patience, I wouldn’t ask the question if it would behave as the documentation “flat out” says – ramzesenok Aug 04 '23 at 20:45
  • If you are seeing different behavior in different situations then it would be helpful to enumerate those situations with code examples so that others can see and try to address the differences as well. – Scott Thompson Aug 10 '23 at 18:32
  • @ScottThompson you’re right. But the behavior only occurs in one test which fails or succeeds based on which value setter I use. All other places works fine so I’m not sure if I can isolate it. So my assumption was “maybe I don’t know something which causes this behavior” – ramzesenok Aug 10 '23 at 23:33

0 Answers0