Questions tagged [property-wrapper-published]
28 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
7
votes
1 answer
Is there a way to access enclosing instance `ObservableObject` to call `objectWillChange.send()` from anywhere in a property wrapper
I'm trying to make a property wrapper similar to Combine's Published one(for my project needs), but with ability to modify the wrapped property by sending a value to a publisher, stored in projectedValue, like this:
// in class
@PublishedMutable var…

mrpaw69
- 155
- 9
3
votes
2 answers
@Published not updating UI on changing value of viewmodel
In my ViewController (UIHostingController) i have viewModel (reference type) shared between ViewController and its rootView. And viewModel has one property which is wrapped as @Published.
On receving response to viewcontroller from api…

user968597
- 1,164
- 2
- 15
- 30
2
votes
1 answer
SwiftUI view not being refreshed when Published object changes
In my view model I have this property and method:
@Published var cats: [Cat] = [] //this gets populated later
When I update one of the cats as such:
func updateCatQuantity(_ cat:Cat, qty: Int) {
if let index = cats(of: cat) {
…

soleil
- 12,133
- 33
- 112
- 183
1
vote
1 answer
How do I get the value of a Published in swift without using debugDescription?
I've got the following code, that runs in a playground.
I'm attempting to allow subscript access to @Published variables in a class.
The only way I've found so far to retrieve the String value in the below implementation of
getStringValue
is to use…

Kem Mason
- 1,548
- 17
- 26
0
votes
0 answers
@Published property wrapper doesn't allow tuple sets
import SwiftUI
class aViewModel: ObservableObject {
@Published var abc: Set<(aa:String,bb:String,cc:Double,dd:Int)> = [] // Type '(aa: String, bb: String, cc: Double, dd: Int)' does not conform to protocol 'Hashable'
func fetchData()…

Radioactive
- 3
- 3
0
votes
1 answer
SwiftUI : Receive Published values with conditions
I have an Observable Object GlobalOO with a @Published value
In any View , I can observe changes with
.onReceive(globalOO.$value){ newValue in ...}
Now I only want to receive those changes according to a condition in the view
@State private var…

Gyh
- 3
- 1
0
votes
1 answer
What is the difference between marking a variable with/without @Published in a class conforming observableObject?
everyone,
I'm currently working on a SwiftUI project and have encountered a question regarding the usage of @Published in a view model. I have a login view with a variable 'errorMessage' in the view model.
I noticed that even when I removed…

Rookie
- 21
- 2
0
votes
2 answers
SwiftUI state management
I have encountered an architectural problem with SwiftUI state.
Consider an architecture with a uni-directional data flow.
class Store: ObservableObject {
@Published private(set) var state: AppState = AppState(initialValue: 0)
func…

Mikayel Aghasyan
- 225
- 2
- 11
0
votes
1 answer
In SwiftUI I have a List that should update when the source array in a Swift class is appended but I get syntax errors that I don't understand
I have an example project to learn how to have a List update when the source array (in a Swift class) updates. I'm pretty green in SwiftUI and Swift. The List View error is:
Initializer 'init(_:id:rowContent:)' requires…

Nate Lockwood
- 3,325
- 6
- 28
- 34
0
votes
2 answers
How to use .fullScreenCover(isPresented: $viewModel.loginSuccessful) with a non bool value
I've got a view that uses the following view modifier:
.fullScreenCover(isPresented: $viewModel.user) {
This will generate a error:
Cannot convert value of type 'Binding' to expected argument type 'Binding'
When the user taps…

xarly
- 2,054
- 4
- 24
- 40
0
votes
0 answers
Do I need to fetch record every time I update existing Core Data Entity object or can i use @published arrays to modify data?
I'm learning SwiftUI and working on a iOS app project with SwiftUI where I have used Core Data for persistent data storage. I've created a global view model and injected it into the environment from top so that I can access it in within my app from…

DevSec
- 1
- 2
0
votes
1 answer
@Published value don't pass through views
I'm beggining with SwiftUI and I wanted to develop a small simple app to practice. I have a problem with @Published property that don't pass through views and so don't update the view.
I explain : In the first view I calculate the vMoyenne property…

torfeuzarre
- 11
- 3
0
votes
1 answer
Does .receive(on:) guarantee @Published property's value been updated once .sink() block is executed?
It's a common mistake to expect that a @Published property's value has been updated when .sink() block is executed. In that case however, the property still has the old value, because .sink() is triggered by willSet (as is explained here).
Some…

meaning-matters
- 21,929
- 10
- 82
- 142
0
votes
0 answers
Unidentified publishing object in SwiftUI Map annotation
Setup:
My app uses a SwiftUI Map with annotations. The annotations should be instances of a Place class defined as:
final class Place: NSManagedObject, UpdateTimestampable, Identifiable {
@NSManaged var horizontalAccuracy: Double
@NSManaged…

Reinhard Männer
- 14,022
- 5
- 54
- 116