I am trying to feed my Widget the information from my class, but for unknown reason for me, the Widget is not able to see and find the Class! here is my class:
import SwiftUI
class AppColor: ObservableObject {
static let shared: AppColor = AppColor()
@Published var color: Color = Color.red
}
here is my ContentView:
import SwiftUI
struct ContentView: View {
@StateObject var appColor: AppColor = AppColor.shared
var body: some View {
ZStack {
appColor.color.ignoresSafeArea()
Button(action: {
if appColor.color == Color.red {
appColor.color = Color.yellow
}
else {
appColor.color = Color.red
}
}) {
Text("change Color")
.foregroundColor(Color.black)
.bold()
}
}
}
}
and here is my Widget:
struct testWidgetEntryView : View {
var entry: Provider.Entry
@StateObject var appColor: AppColor = AppColor.shared
var body: some View {
appColor.color
}
}
and here is my file positions in app: