Created
May 29, 2022 10:51
-
-
Save YusukeHosonuma/9ec8007f53106a70583a73cd39935ee8 to your computer and use it in GitHub Desktop.
レベルの高い SwiftUI 面接(仮)
This file contains hidden or 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
| // | |
| // 元ツイート: | |
| // https://twitter.com/tobi462/status/1529687893811556354?s=20&t=LUmtHH5wXylCFqTQpfgyVg | |
| // | |
| // ボーナス問題: | |
| // https://twitter.com/tobi462/status/1529727505313124353?s=20&t=LUmtHH5wXylCFqTQpfgyVg | |
| // | |
| struct ContentView: View { | |
| @State var text: String = "🍎" | |
| @State var message: String = "Hello" | |
| @State var xs: [Int] = [0, 1, 2, 3] | |
| var body: some View { | |
| let _ = Self._printChanges() // ① | |
| VStack { | |
| Button("Touch") { | |
| text = "🍊" // ② | |
| message = "Swift" | |
| } | |
| Text(text) | |
| Text(message) | |
| } | |
| .onChange(of: text) { _ in | |
| let x = xs.removeFirst() // ③ | |
| text = "🍌 \(x)" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment