Questions tagged [currentvaluesubject]
5 questions
32
votes
5 answers
Difference between CurrentValueSubject and @Published
So I'm digging into combine and this question came up.
Is there any real difference between using CurrentValueSubject (and setting its value using currentValueSubject.value) or using a @Published var and accessing its publisher with a $? I mean I…

Mykod
- 587
- 1
- 5
- 16
0
votes
0 answers
CurrentValueSubject: ignore the first value on subscribe and trigger update only if there is already a value
Code:
private var _nwPathStatusSubject: CurrentValueSubject = .init(.satisfied)
private var networkPathStatusPublisher: AnyPublisher {
_nwPathStatusSubject
.removeDuplicates()
…

Richard Topchii
- 7,075
- 8
- 48
- 115
0
votes
1 answer
Using NotificationCenter with CurrentValueSubject
I am new to Combine. I understand we can send values with NotificationCenter's combine implementation like this:
let myNotification = Notification.Name("myNotification")
class Cat {
var breed : String
init(breed: String) {
…

incelemeTRe
- 43
- 1
- 4
0
votes
0 answers
Thread safety of updating a Subject value in Combine?
Lets say I have a struct state like this
struct SomeState: Equatable {
var counter: Int = 0
var foo: Bool = false
}
and then a subject of private let _state = CurrentValueSubject(SomeState())
I know I can update it as _state.value.counter…

urSus
- 12,492
- 12
- 69
- 89
-1
votes
0 answers
Difference in CurrentValueSubject value setting
Swift's Combine's CurrentValueSubject offers 2 ways to change the underlying value:
subject.value = newValue
subject.send(newValue)
Is there anything fundamentally different in these 2 lines? I think I notice the inconsistencies sometimes in terms…

ramzesenok
- 5,469
- 4
- 30
- 41