Questions tagged [observableobject]
262 questions
0
votes
1 answer
Why is my @ObservedObject not performing changes in my view?
I have a simple Loader that performs a loading animation when its @Publisher is set to true. This publisher is set to true on a ViewModel when making a network request. I would like this value to change my view, which it doesn't. The ContentView…

Roland Lariotte
- 2,606
- 1
- 16
- 40
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
0 answers
SwifUI complex memory leak in forEach with EnviromentObject
i have a strange memory leak with this code:
class Test: ObservableObject {
@Published var test:[TestStruct] = []
func getTest() {
guard let url = URL(string: "https://www.test.com") else {
return
}
…

Stefano Vet
- 567
- 1
- 7
- 18
0
votes
1 answer
SwiftUI ObservableObject and Published issue
here is something that keeps me awake for three days already: I'm writing a little app that connects via BlueTooth to an Arduino. To get visual feedback about the connection state and the transmitted data, I use a view that allows me to…

Christian
- 37
- 7
0
votes
0 answers
How to avoid Fatal error: No ObservableObject of type ... in SwiftUI?
I trimmed things down to this very simple example (a vanilla SwiftUI project, edit only ContentView and one line in SceneDelegate). Sets up a trivial ObservableObject and a couple of Views for screens. With latest Xcode 11.4 and simulator crashes…

James
- 1,985
- 18
- 19
0
votes
0 answers
How to save/retrieve from a DatePicker using UserDefaults in SwiftUI?
I'm trying to use a DatePicker to select a specific time of day, then once that time is selected, save the time as an ObservedObject and save it to my UserDefaults using SwiftUI. The problem with my code below is that while the data gets saved after…

Jason Rueckert
- 661
- 2
- 6
- 14
0
votes
3 answers
How to replace @FetchRequest by dynamic call
I have this code in my SwiftUI project in works well
struct ContentView: View {
@State private var selectedCountry: Country?
@State private var showSetting = false
@FetchRequest(entity: Country.entity(),
sortDescriptors:…

Dawy
- 770
- 6
- 23
0
votes
1 answer
Remove objects from ObservableObject
Two ViewModels, one is a store of roles containing skills:
final class RolesStore: ObservableObject {
@Published var roles: [Role] = []
.....
A role model is:
struct Role: Codable, Identifiable {
let id: String
var name: String
var…

Ivan C Myrvold
- 680
- 7
- 23
0
votes
1 answer
SwiftUI - deletion of elements in Binding Array causes errors
I'm developing an App (using Xcode 11.3.1, target device: iPad) for our company's engineers to report on work they do. Part of the app needs to be an editable list of parts they've used.
I've replicated the mechanisms I'm trying to implement…

philslinkee
- 15
- 8
0
votes
1 answer
UI freezes and is slow to populate results when content is filtered with SearchBar
I finally have working code to search an array of objects but it's really slow to populate/show the list results in a view. I've been looking into using ObservableObject and EnvironmentObject but I'm not sure how to implement them here. I'm…

Mdoyle1
- 121
- 1
- 12
-1
votes
1 answer
SwiftUI View Model State, the view doesn't update
Here is a simple representation of what I'm trying to do. I need to have a view updated when values change in a class stored inside a published var. This ContentView should be updated when Items is updated in the ItemManager stored in the state of…

Jonathan
- 55
- 6
-1
votes
1 answer
UserDefaults, ObservableObject and SwiftUI
I'm a little confused on how ObservableObject works with UserDefaults and could use some assistance.
I have a data struct that I need to save when a Background Fetch task runs. When the user resumes the app, I want the new data to be displayed.
As…

FlatDog
- 2,685
- 2
- 16
- 19
-1
votes
1 answer
Newtonsoft.Json.JsonSerializationException: Error setting value to 'StringProperty' on 'MyComponent' with inner ArgumentNullException
I'm attempting to create a 'Has Been Edited' tracker for my component classes, like this:
public class MyComponent : ObservableObject
{
// If any changes are made to properties that have the InspectableAttribute, this becomes true.
public…

Thomas Slade
- 129
- 9
-1
votes
1 answer
SwiftUI using ObservableObject with Binding cause sheet crash
I have View with button that display sheet and after first sheet dismiss, I need to display a second sheet, when I use ObservableObject in Binding the View crash after showing the second sheet:
Root:
class Benef: ObservableObject {
@Published…

OuSS
- 19
- 3
-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…

Kamil Sko
- 1
- 4