Questions tagged [property-wrapper-published]

28 questions
0
votes
1 answer

Swift : Publishing data from one class to another not working (Apple HealthKit)

class HealthKitQueryBuilder import Foundation import HealthKit class HealthKitQueryBuilder:ObservableObject { let healthStore: HKHealthStore let dateFormatter = DateFormatter() @Published var hourlyStpCount: [HealthData]? …
0
votes
0 answers

How to insert functions within an array using user-defined published variables

Here is the desired result (a List from a viewModel derived using functions to generate yearly pay raises and show user's age from year to year). When the user alters their birthdate and hiredate in the ProfileFormView, this List should update the…
0
votes
1 answer

SwiftUI: View does not update with user input in Form fields/pickers

I can't seem to get my "Employee View" to update based on user input in the Form inside the "ProfileFormView." Currently any input in the Form fields does not affect the "EmployeeView". I need the data that is typed into the Form to update the…
0
votes
0 answers

SwiftUI: Cannot use instance member 'x' within property initializer; property initializers run before 'self' is available

Four errors: I don't understand why these complier errors are occurring. Did I not initialize "name", "empNum", "birthdate" and "department"? @MainActor class EmployeeViewModel: ObservableObject { @Published var name = "" @Published var empNum =…
0
votes
0 answers

How to use a publisher in base class and observe changes in two different subclasses?

I have a base class where I'm making an api call and changing the state of the api like so class ProfileBaseViewModel { @Published private(set) var apiState: APIState = .initial private(set) var settingsData: SettingModel? var…
Ameya Vichare
  • 1,119
  • 1
  • 10
  • 22
0
votes
1 answer

SwiftUI, How to publish data from view to a viewModel then to a second view?

I have one view (with a Form), a viewModel, and a second view that I hope to display inputs in the Form of the first view. I thought property wrapping birthdate with @Published in the viewModel would pull the Form input, but so far I can't get the…
0
votes
2 answers

Changing text view - showing progress lengthy operation

I'm trying to show progress of a lengthy operation in a Text view. Using StateObject/Published var, I was hoping to see the Text change when the published var changes, however, I only see the last text appearing in the Text field. How can I…
WimJanse
  • 13
  • 2
0
votes
1 answer

Pass a published property as binding

I have an ObservableObject with a published dictionary of strings to arrays with arrays with Ints: class MyObservableObject: ObservableObject { @Published var myDict: [String: [[Int]]] } And I want to pass one array of Ints as a Binding from…
-1
votes
1 answer

How to receive notification of changes to any ViewModel property using subscribers?

I'm starting coding in Swift, but trying to make an app well, using best practices. Application should control Philips Hue bridge to change lights states in home. It reads and send http requests from the Hue bridge and must sync it with visible…
-1
votes
2 answers

How to force a refresh of a SwiftUI View?

I have a button with a .disabled() condition that's a computed property of my ObservableObject model class. This means I can't make it @Published. Something like this: class MyModel : ObservableObject { var isDisabled: Bool { if ... { …
meaning-matters
  • 21,929
  • 10
  • 82
  • 142
-1
votes
1 answer

How to make 'Published<[String]>.Publisher' conform to 'RandomAccessCollection'

I am trying to make a view that updates based on if the user toggles the favorite button or not. I want the entire view to reconstruct in order to display an array of values whenever that array of values is changed. Inside the view, a for each loop…
-1
votes
1 answer

My published variables in my view Model get reset to their default values when i run the code

I have been having problems with updating a published variable in my model, so I tried to replicate the problem with a very basic and simple set of files/codes. So basically in NavLink view, there is a navigation link, which when clicked, it updates…
-2
votes
3 answers

Changing a `Published` property of an `ObservableObject` to a computed var

I have an ObservableObject with @Published properties: class SettingsViewState: ObservableObject { @Published var viewData: SettingsViewData = .init() … I would like to change viewData to a computed var based on other sources of truth…
Benjohn
  • 13,228
  • 9
  • 65
  • 127
1
2