Skip to content

Instantly share code, notes, and snippets.

@hexagit
Created November 15, 2019 04:22
Show Gist options
  • Save hexagit/85388ea4acf1792f1f4701d89ed50488 to your computer and use it in GitHub Desktop.
Save hexagit/85388ea4acf1792f1f4701d89ed50488 to your computer and use it in GitHub Desktop.
//ObservableObject:監視対象に指定
class Observable: ObservableObject {
//Published:変更を自動通知
@Published var wordData: [Word] = load("wordList.json")
}
struct ContentView: View {
@ObservedObject var words = Observable()
var listRows : [ListRow] = []
var body: some View {
//垂直並べ
VStack {
//水平並べ
HStack {
//リセットボタン
Button(action: {
ResetWords()
}){
Text("Reset")
}
Spacer()
//書き込みボタン
Button(action: {
writeJSON()
}){
Text("Write")
}
}.frame(width:300,height: 50)
//リスト表示
List{
//単語一覧
ForEach(words.wordData, id: \.self) { word in
//子要素に単語データ渡す
ListRow(word: word).environmentObject(self.words)
}
//追加テキスト・追加ボタン
InputRow().environmentObject(self.words)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment