Questions tagged [observedobject]

@ObservedObject is a SwiftUI property wrapper used to mark properties that are not owned by the View, but should update the View. Only ObservableObject conformant types can be annotated with the @ObservedObject property wrapper.

For more info, see the official documentation of @ObservedObject.

173 questions
0
votes
2 answers

ObservedObject being loaded multiple times prior to navigation to its view

having a bit of trouble with the following. I have a List in a VStack as follows: List{ ForEach(fetchRequest.wrappedValue, id: \.self) { city in NavigationLink(destination: CityView(city: city, moc: self.moc))…
0
votes
1 answer

IOS 14 adding ObservedObject to a var causes views not to appear on iPhone

I am working through the examples from Stanford's online CS139p. The cards for the memory game are drawn. I make the viewModel an ObservableObject, I publish the var that represents the memory game, and run the app. Everything happens as I expect. I…
0
votes
1 answer

SwiftUI height animation of a text frame when @ObservedObject change

I try to make a smooth animation when the NetStatus change but it's not working like i want. I want to get the same effect as when i press the button with the toggle animation. The commented button animation is working great and i try to replicate…
Flincorp
  • 751
  • 9
  • 22
0
votes
1 answer

SwiftUI @ObservedObect View Model Index out of Range

In Swift I have a viewModel which connects to FireStore and when I call its function fetchData it returns a number of documents successfully. But when I try to reference a document using an index I get an Out of Range error. In this example the…
Jmcg
  • 239
  • 2
  • 9
0
votes
1 answer

Can not Reach to Array Element from Another View SwiftUI

GitHub Project Link I have a creditCard Model and CreditCards class that has a function to append creditCard. class CreditCard: ObservableObject, Identifiable { @Published var _id: String = UUID().uuidString @Published var _cardOwnerName : String =…
Mert Köksal
  • 817
  • 1
  • 7
  • 26
0
votes
2 answers

SwiftUI - How to create an edit view for each list view item based on @ObservedObject

I have created a simple example of the problem I'm facing. I have two views, ListView and EditView. ListView is observing the UsersViewModel (plural) which contain a list of user names. Using NavigationLink I want to present a form where I can…
Jmcg
  • 239
  • 2
  • 9
0
votes
2 answers

SwiftUI didn't update the view while observedObject changed

I'm doing a login and display data application. While the user login, the data will be displayed correctly. While I logout and login another account, the data supposed to be update by the observedObject which call the function to be reload the data.…
SAS231
  • 175
  • 4
  • 17
0
votes
0 answers

Stored result of json decode is suddenly gone/ Observed Object doesn't react in WatchOS

I decode json data from an iPhone to a watch and store it into an object (custom class: PeopleObj) which is declared as @ObservableObject. However, the contenview containing this object doesn't get the data This is the data model: struct Person:…
Red
  • 1,425
  • 1
  • 10
  • 15
0
votes
1 answer

SwiftUI ObservedObject not updating view after successful login

To show my the content from my root view after successful login, I tried with ObservedObject, and with EnvironmentObject, to no avail. E.g. as follows: struct RootView: View { @EnvironmentObject var loginManager: LoginManager var body:…
Mundi
  • 79,884
  • 17
  • 117
  • 140
0
votes
1 answer

Using @observable in Swift, I want to periodically refresh the ObservedObject using a timer. How do I do this?

I am writing an app that pulls data from a website and displays it using SwiftUI. My main view has an @ObservedObject which is of type DataStore(), and which is used in the view: struct ContentView: View { @ObservedObject var store =…
Michael Shulman
  • 643
  • 5
  • 6
0
votes
1 answer

One ObservedObject needs to take in another ObservedObject as an argument; how do you do this?

struct ContentView { @ObservedObject var annotationsVM = AnnotationsVM() //I'd like to pass in the ViewModel() declared below into annotationsVM like AnnotationsVM(VModel: Vmodel) @ObservedObjects var VModel = ViewModel() var body:…
nickcoding
  • 305
  • 8
  • 35
0
votes
1 answer

why my ObservedObject is updated but not showing its updated content in the View

I trying to show a simple View of counting down the time using ObservableObject but it seems my ObservedObject is updated but not showing its updated content to its binded view. The display stay at 60 import SwiftUI import Combine class myTimer:…
FLMikeN
  • 1
  • 1
0
votes
1 answer

When an ObservedObject passed into a view is updated, the SwiftUI doesn't update?

I have a view called SearchResults. It should update whenever the ObservedObject passed into it changes, but the View is not updating with the new values and I'm not sure why. import SwiftUI struct SearchResults: View { @ObservedObject var…
nickcoding
  • 305
  • 8
  • 35
0
votes
1 answer

How to keep reference of data when using ObservableObject

I am new to Swiftui and I struggle to understand how to properly retain data created in ObservableObject when rendering views? Or a completely different approach to the problem maybe? More specifically, it is about getting HTTP data in each row in a…
Stefan Edberg
  • 231
  • 2
  • 4
  • 15
0
votes
2 answers

SwiftUI with JSON ObservedObject

Im currently learning SwiftUI and I'm having trouble getting my code to print the call from the API NetworkManager.swift class NetworkManager: ObservableObject { @Published var allCountries = Countries() func fetchAllCountries() { …
Jay_EL
  • 69
  • 1
  • 7
1 2 3
11
12