Questions tagged [observableobject]
262 questions
3
votes
2 answers
SwiftUI ObservedObject causes undesirable visible view updates
I am working on an app that applies a filter to an image. The filter has a number of parameters that the user can modify. I have created an ObservableObject that contain said parameters. Whenever one of the parameters changes, there is a visible…

Jack Goossen
- 799
- 4
- 14
3
votes
2 answers
How to swap my @State of my SwiftUI view for my view model @Published variable?
I have a button that triggers my view state. As I have now added a network call, I would like my view model to replace the @State with its @Publihed variable to perform the same changes.
How to use my @Published in the place of my @State…

Roland Lariotte
- 2,606
- 1
- 16
- 40
3
votes
1 answer
ObservableObject with NWPathMonitor
I try to make NWPathMonitor an observable object that returns true if there is a network connection and false if not.
Can you help me because my solution doesn't work.
Thanks
import Foundation
import Network
class TestNetStatus: ObservableObject…

Flincorp
- 751
- 9
- 22
3
votes
1 answer
How can I update value of TextField in SwiftUI?
So, I want change cursor position after update TextField's value (input mask like "+7 000 000 00 00").
I have TextField:
TextField("+7 000 000 00 00", text: $loginChecker.login)
.textContentType(.telephoneNumber)
…

Nikita Romanovich
- 31
- 3
3
votes
2 answers
SwiftUI Observe Changes
Overview:
I have a class called Player and a class called Song.
Player contains a Song
A view is showing the song title
Aim:
When I change the player.song.title, the view needs to be updated.
Problem:
When the song's attributes changes, it…

user1046037
- 16,755
- 12
- 92
- 138
3
votes
1 answer
SwiftUI, How to dismiss current presenting View when API call returns successfully
I am using SwiftUI and I am trying to achieve a simple logical action but unable to understand SwiftUI action hierarchy.
I have one API call something like this,
final class TaskData: ObservableObject {
@Published var updatedFields = false
…

Najam
- 1,129
- 11
- 32
3
votes
1 answer
Passing an ObservableObject model through another ObObject?
I feel like I can sort of understand why what I'm doing isn't working but I'm still trying to wrap my head around Combine and SwiftUI so any help here would be welcome.
Consider this example:
Single view app that stores some strings in UserDefaults,…

Sparklebeard
- 808
- 6
- 15
2
votes
1 answer
SwiftUI how to update data in a View Model with data from another View Model
I am trying to update @Published arrays in separate view models, one view model is a singleton whilst the other is not as there can be multiple instances.
The purpose of the code below is to allow a user to save or unsave
movie recommendations to…

IamActuallyIronMan
- 75
- 7
2
votes
2 answers
Dismissing view using ObservableObject class provokes Publishing changes from within view updates is not allowed
When dismissing a fullScreenCover using a variable inside an ObservableObject (lines commented with 1.-) it shows the "Publishing changes from within view updates is not allowed, this will cause undefined behavior." message in the console, but using…

rai212
- 711
- 1
- 6
- 20
2
votes
3 answers
Do I have to use an ObservableObject in SwiftUI?
I would like to use a struct instead of a class as a state for my View, and as you may know, ObservableObject is a protocol only classes can conform to.
Do I have to wrap my struct in a ViewModel or some other similar type of object ? What happens…

ice-wind
- 690
- 4
- 20
2
votes
1 answer
Detail View from different Data Model (API response) in swiftUI
Elaborating the Problem in depth with code
I have a data model (API response) using which I am creating a list. The list items should also display their details in detail view. The problem is details of list items are coming from a different API…

tintin
- 335
- 2
- 8
2
votes
1 answer
Passing variable from view inside the class ObservableObject?
i got this struct
struct Calendar: View {
@State private var selectDate = Date()
var body: some View {
// my code
}
Class fetchmydate: ObservableObject {
func fetchmydata (){
// i want to pass selectDate to here in "dd-mm-yyyy" format as…
user18276412
2
votes
2 answers
SwiftUI: Binding on property of struct derived from environment object
I have two structs in my task manager app:
struct Task {
var identifier: String
var title: String
var tags: [String] // Array of tag identifiers
}
struct Tag {
var identifier: String
var title: String
}
I then have a class to…

Chris Schlitt
- 133
- 3
- 12
2
votes
1 answer
SwiftUI: State variable from observed singleton property leads to error
I use a singleton to access subscription offerings from RevenueCat as an @ObservedObject on various views in the app:
import Foundation
import Purchases
import SwiftUI
class SubscriptionManager: ObservableObject {
static let shared =…

FrankZp
- 2,022
- 3
- 28
- 41
2
votes
2 answers
How to update an element of an array in an Observable Object
Sorry if my question is silly, I am a beginner to programming. I have a Navigation Link to a detail view from a List produced from my view model's array. In the detail view, I want to be able to mutate one of the tapped-on element's properties, but…

pakobongbong
- 123
- 1
- 9