Questions tagged [observableobject]

262 questions
0
votes
1 answer

How to use Observable Objects with this class?

I'm trying to use Observable Objects with this class:- class malaysiaHolidays: ObservableObject { @Published var holidayName : String @Published var holidayDate : String init(holidayName: String, holidayDate:…
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

Is there a way to detect changes in a Swift ObservableObject by hooking into the subscriber pipeline without all the didChange plumbing?

I'm creating a SwiftUI app with various View Model objects to support the views. On some views, where the user can leave without saving changes, e.g. 'Cancel' I want to prompt a confirmation if the underlying view model has any changes. Some of the…
Steven Wilber
  • 405
  • 6
  • 10
0
votes
2 answers

ObservedObject not triggering view redraw

I've a view which requires data obtaining from an api. My understanding of SwiftUI is that by using onAppear the api will be called, viewmodel attribute updated, and the StateObject changed which will trigger a View redraw. The issue is that no…
Houdi
  • 136
  • 10
0
votes
1 answer

Segmentation 11 non zero exit code error in SwiftUI in Xcode

error: Segmentation fault: 11 (in target 'ProjectName' from project 'ProjectName') Command CompileSwift failed with a nonzero exit code Both of these errors are present when the following file is in my project: import Foundation import…
nickcoding
  • 305
  • 8
  • 35
0
votes
2 answers

Trying to Bind an ObservableObject but getting Cannot assign to property: 'XXXX' is a get-only property Error

I am quite new in Swift and SwiftUI and I am getting a error that I cannot understand. Here is my class that I load with JSON from a web service class ResaListViewModel: ObservableObject { @Published var resasDeparts = [ResaViewModel]() …
Godefroy
  • 46
  • 4
0
votes
2 answers

Push the navigation link with the updated @published variable

I updated the published var chats in a sheet. And when the sheet is dismissed (by button press), the MessageView navigates to ChatView. I hope to use that updated chats in the ChatView, but now when it's first pushed, chats isn't updated, until you…
0
votes
1 answer

How binding between computed property in model and view's @Binding property in SwiftUI

I trying make a API Tester app about restful. my model stored a few property, scheme protocol like “http”,host like “www.google.com”,path like “/search” and query parameter like “?q=keyword”. and a computed property about URL string ,it joined from…
ave marina
  • 21
  • 2
0
votes
1 answer

Observable object not working with Published keyword

I am trying to write a property wrapper to access userDefaults but have two problems. The code snippet is as below User Default wrapper @propertyWrapper struct UserDefault { private let key: String private let defaultValue: T private…
0
votes
1 answer

How to store user data locally in SwiftUI

I try to accomplish having an observable object with a published value training. On every change it should save the custom struct to the user defaults. On every load (AppState init) it should load the data: class AppState: ObservableObject { …
T. Karter
  • 638
  • 7
  • 25
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
0 answers

Subview does not render Published value update in ObservableObject class within a child view

I have a subview which is a List containing a ForEach on a Published array variable from an ObservedObject. The subview is displayed within a TabView and NavigationView on the main ContentView. However, the List does not render the updated array…
user3816540
0
votes
1 answer

Pointing to All Three views inside SwiftUI from a ViewRouter and ObservableObjects or environmentObject's

I have been using SwiftUI lately, and I have managed to write in ContentView.swift as my rootView, including 2 buttons to change to other "pages" or "screens" within an app. Currently, I am able to move between Two views in my code. I used…