Skip to content

Instantly share code, notes, and snippets.

@YusukeHosonuma
Created May 29, 2022 10:51
Show Gist options
  • Select an option

  • Save YusukeHosonuma/9ec8007f53106a70583a73cd39935ee8 to your computer and use it in GitHub Desktop.

Select an option

Save YusukeHosonuma/9ec8007f53106a70583a73cd39935ee8 to your computer and use it in GitHub Desktop.
レベルの高い SwiftUI 面接(仮)
//
// 元ツイート:
// 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