Questions tagged [observableobject]
262 questions
1
vote
1 answer
SwiftUI: No ObservableObject of type Y found, where Y is a subclass of an ObservableObject
SwiftUI errors like this appear frequently on StackOverflow:
Thread 1: Fatal error: No ObservableObject of type Foo found. A View.environmentObject(_:) for Foo may be missing as an ancestor of this view.
The answer is always to pass a Foo instance…

NRitH
- 13,441
- 4
- 41
- 44
1
vote
1 answer
Updating a Scroll View with a global array
On my main screen I have a Scroll View which I want to display all of the events that are happening within the app. Currently I have this defined as a global variable as shown below:
struct matchEvent: Identifiable{
var id = UUID()
var…

benpomeroy9
- 375
- 5
- 21
1
vote
1 answer
Passing Lat/Long to function in SwiftUI
I am building a SwiftUI app that shows data based on user lat/long. I have based my code off of this sample provided by the framework dev.
With SwiftUI I have my LocationManager set as:
class LocationViewModel: NSObject, ObservableObject,…

Efrain Ayllon
- 17
- 2
1
vote
1 answer
ObservableObject with ObservableObject property is not triggering SwiftUI Update
// NavigationState.swift
class NavigationState: ObservableObject {
@Published var contentViewNavigation = ContentViewNavigationState()
//@Published var selectedTab = 0
}
// App.swift
@main
struct SwiftUIDeepLinkApp: App {
@StateObject…

José Roberto Abreu
- 176
- 1
- 14
1
vote
1 answer
Swift How to reload an Environment-Object
I want to add a Button to my view to load more data. In my Environment Object the data is generated randomly via an API.
How can I reload my Environment object to get new items. The Code Below should make it clear. Thanks in advance
class observer…

Tobi.M
- 17
- 3
1
vote
1 answer
ObservableObject is missing in Motherview
I have the following viewfile:
import SwiftUI
class Progress: ObservableObject {
@Published var index = 0
}
struct RegistrationView: View {
@ObservedObject var progress: Progress
var body: some View {
TabView(selection:…

Tim4497
- 340
- 3
- 19
1
vote
1 answer
Get @EnvironmentObject to NSObject class
I have a simple ObservableObject class which I initialize in the App.swift file and pass to the first view:
final class Counter: ObservableObject {}
@main
struct MyCoolApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self)
private var…

Gargoyle
- 9,590
- 16
- 80
- 145
1
vote
1 answer
SwiftUI ObservableObject create non array @Published
I tried to create an ObservableObject with non array @Published item. However, I still don't know how to do so. I tried to use a ? to do so. But when I display it in view like Text((details.info?.name)!), and it return Thread 1: Swift runtime…

Oxford212
- 89
- 1
- 8
1
vote
0 answers
Bindings all of sudden not working in iOS14
Prior to iOS 14 my project was working fine with the following code
struct LoginView: View, Resolving {
@ObservedObject var loginUIService: LoginUIService = Resolver.resolve()
...
var body: some View {
...
…

BrettS
- 295
- 6
- 14
1
vote
1 answer
SwiftUI - Trigger a Modal Sheet from an ObservableObject?
I've created a random number generator that should present a new sheet if the number 3 appears.
The logic is in a separate class but when I use .sheet or .fullScreenCover on the ContentView it doesn't work.
Is it possible to trigger a modal sheet…

Thom Sides
- 117
- 1
- 7
1
vote
0 answers
How does a ObservableObject observe the change of Binding value (not value type)
Code:
class AppStore: ObservableObject {
@Published var settings = Settings()
}
struct Settings {
var account = Account()
}
class Account {
@Published username
}
@EnvironmentObject appStore = AppStore()
VStack {
…

user14232309
- 11
- 1
1
vote
1 answer
SwiftUI can't bind class array parameter
In my SwiftUI project I have a button class model:
import SwiftUI
import Combine
class Button: Identifiable, ObservableObject {
var id = UUID()
@Published var title = String()
init(title: String) {
self.title = title
…

Riccardo Perego
- 383
- 1
- 11
1
vote
1 answer
Swifui: MacOS App: Fetching Core Data in ContentView OK, but how to use the result from AppDelegate?
With Xcode 11.6 (11E708), SwiftUI, for a MacOS app, I have data generated in the ContentView.swift. But I cannot use those data inside the AppDelegate.swift:
Build Succeeded but the print(contentView.order.item) (please see below) produce this…

kali mera
- 13
- 4
1
vote
1 answer
SwiftUI View not updating when Published variable is changed
On a button press, I my app is trying to contact an api to receive data. This data is then stored in a published variable inside an observable object. For some reason, the view doesn't populate with the data until the button that opens that view is…

TJ D'Alessandro
- 109
- 1
- 19
1
vote
1 answer
UITextField not updating to change in ObservableObject (SwiftUI)
I am trying to make a UITextView that edits a value currentDisplayedAddress. The value is also changed by other views, and I want the UITextView to update its text when that occurs.
The view initializes correctly, and I can edit…

Calvin Xu
- 39
- 5