Questions tagged [observableobject]

262 questions
2
votes
0 answers

Child view of NavigationView automatically returning to parent view when variable changes

I'm working through the Apple SwiftUI tutorials, and I'm encountering an issue where child views automatically return to the parent view whenever they change a variable in an @EnvironmentObject. The parent LandmarkList view functionality allows…
2
votes
1 answer

How do I create a http connection using environment variables that are stored as UserDefaults in swiftui?

I'm new to swift/swiftui programming. I have two environment variables that user puts in through TextFields. Based on these two text fields, I have to initialise my client. I used UserDefaults instead of the EnvironmentObject because these two…
syllogismos
  • 600
  • 2
  • 15
  • 39
2
votes
1 answer

Passing parameter value to Observable object

I have an ObservableObject class used to fetch data from an api. It takes one parameter which is the api key. I am trying to pass that key from a parameter of my ContentView to the object. class UnsplashAPI: ObservableObject { //some code …
Arnav Motwani
  • 707
  • 7
  • 26
2
votes
1 answer

How do I catch a value change that was changed via a function in SwiftUI?

My View don't check that's the value has changed. Can you tell me why or can you help me? You can see below the important code. My Class import SwiftUI import SwiftyStoreKit class Foo: ObservableObject { @Published var Trigger : Bool = false …
Aiiboo
  • 613
  • 2
  • 6
  • 13
2
votes
1 answer

Linker error when using Swift ObservableObject from Objective-C

I am trying to use a Swift class from Objective-c (as I do for many other classes) with the following error. Undefined symbol: OBJC_CLASS$__TtC9FileCloud18BrowserCoordinator The issue seems to be that this particular class conforms to the Swift…
Rivera
  • 10,792
  • 3
  • 58
  • 102
2
votes
1 answer

Array of binding variables for multiple toggles in MVVM pattern in SwiftUI

I have a simple use case of having a VStack of a dynamic number of Text with Toggle buttons coming from an array. import SwiftUI public struct Test: View { @ObservedObject public var viewModel = TestViewModel() public init()…
Subha_26
  • 440
  • 4
  • 14
2
votes
2 answers

Swiftui ObservableObject with array not update view

I have a problem with Array using ObservableObject in my view. I have an empty array. I call a function at page onAppear. When the data is returned, the view does not update with the new data in array: class NewsState: ObservableObject { …
Stefano Toppi
  • 626
  • 10
  • 28
2
votes
1 answer

SwiftUI LoginView not disappearing after login

I am using an AppStateView() to check for a user being logged in or not: struct AppStateView: View { @EnvironmentObject var appState: AppState var body: some View { if (self.appState.user != nil) { return…
T. Karter
  • 638
  • 7
  • 25
2
votes
0 answers

SwiftUI and ObservableObject ViewModels causes memory leaks, any example how should I use Combine in ObservableObject

I have such example ViewModel and what I can see in Instruments is that such and similar ViewModel is leaking memory class SearchViewModel: ObservableObject { @Published var searchTerm : String = "" @Published var results: [T] = [] …
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
2
votes
1 answer

How To Resolve a "Thread 1: Fatal error: No ObservableObject of type,,," Crash Message

I am a total rookie to coding, and this is my first project. I have created an app that determines the risk of CardioVascular Disease(CVD) based on the data from cholesterol panel lab tests.The app runs on the iPhone XR (canvas simulator) with no…
docmarroc
  • 21
  • 3
2
votes
2 answers

Is there a way to call assign() more than once in Swift Combine?

I would like to update some variables with values received when handling a newly published value. For example, given: class ProductViewModel: ObservableObject { @Published var PublishedX: Int = 0 @Published var PublishedY: Int = 0 …
chustar
  • 12,225
  • 24
  • 81
  • 119
2
votes
2 answers

SwiftUI - onReceive not being called for an ObservableObject property change when the property is updated after view is loaded

I have a view that displays a few photos that are loaded from an API in a scroll view. I want to defer fetching the images until the view is displayed. My view, simplified looks something like this: struct DetailView : View { @ObservedObject var…
Lauren
  • 281
  • 2
  • 7
2
votes
3 answers

How do I make the Observable Object update the list?

So I know my items are being added to the 'vitallist'(through printing the list in the terminal), but I am not seeing them appear on list view. I think it has something to do with the 'ObservedObject' not being linked correctly. Any suggestions?…
2
votes
0 answers

How do I pass a String from the user input in a SwiftUI TextField to a ViewController view?

I have a SwiftUI application. For the purposes of this, it is 3 views: NewPost (SwiftUI view that contains a TextField) RecordVideoViewWrapper (which references RecordView, which references the RecordVideoViewController in…
AryaG
  • 21
  • 1
2
votes
1 answer

SwiftUI Observable not being updated when using a variable

For some reason, when assigning an object of Observable to a variable and then changing it - the view won't update. but If I access it by its index directly - it will: Won't work: var people = self.mypeople.people[0] people.name = 'test' Does…
Guy S
  • 622
  • 6
  • 13