Created
November 15, 2019 04:22
-
-
Save hexagit/85388ea4acf1792f1f4701d89ed50488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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