Avatar
Deleted User 7/9/2020 6:42 AM
質問です。 EnvironmentObjectで作成した配列をForm内のPickerで選択できるようにしたいのですが、動作がうまくいきません。 シミュレータで動かそうとすると、エラーが起きてしまいます。 エラー文 '''Thread 1: Fatal error: No ObservableObject of type HistoryEntity found. A View.environmentObject(_:) for HistoryEntity may be missing as an ancestor of this view.''' コード //Data.swift import SwiftUI import Combine class HistoryEntity: ObservableObject{ @Published var UserName:[String] = [] } //AddView.swift @EnvironmentObject var histroy: HistoryEntity var body: some View { NavigationView { Form { Picker(selection: $Selection, label: Text("name")) { ForEach(0..<histroy.UserName.count){ Text(self.histroy.UserName[$0]) } } } } (edited)