Hi,
I know, it doesn’t make sense(2 objects the same type).
but I just wanna figure out about @EnvironmentObject
Does a view can only own an @EnvironmentObject?
struct KuchiApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelefate
let user1: UserManager
let user2: UserManager
var body: some Scene {
WindowGroup {
StarterView()
.environmentObject(self.user1)
.environmentObject(self.user2)
}
}
init() {
let user1 = UserManager()
user1.profile.name = "User1"
self.user1 = user1
let user2 = UserManager()
user2.profile.name = "User2"
self.user2 = user2
}
}
struct StarterView: View {
@EnvironmentObject var userModel1: UserManager
@EnvironmentObject var userModel2: UserManager
var body: some View {
VStack {
Text(self.userModel1.profile.name)
Text(self.userModel2.profile.name)
}
.frame(width: 200.0, height: 300.0)
.border(.red)
.padding()
}
}