Created
July 1, 2020 03:24
-
-
Save tehillim/b8b8429bfcc0db7849e7fc8a0763eb5f to your computer and use it in GitHub Desktop.
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
| // | |
| // ContentView.swift | |
| // StateBindingExample | |
| // | |
| // Created by Jèwon Bong on 2020/07/01. | |
| // Copyright © 2020 Appetizer. All rights reserved. | |
| // | |
| import SwiftUI | |
| struct ContentView: View { | |
| @State var isPlaying: Bool = false | |
| var body: some View { | |
| VStack { | |
| InfoWidget(isPlaying: $isPlaying) | |
| ControllerWidget(isPlaying: $isPlaying) | |
| } | |
| } | |
| } | |
| struct InfoWidget: View { | |
| @Binding var isPlaying: Bool | |
| var body: some View { | |
| Text(self.isPlaying ? "Playing.." : "Stopped") | |
| } | |
| } | |
| struct ControllerWidget: View { | |
| @Binding var isPlaying: Bool | |
| var body: some View { | |
| Button(action: { | |
| self.isPlaying.toggle() | |
| }) { | |
| Image(systemName: self.isPlaying ? "stop" : "playpause") | |
| } | |
| } | |
| } | |
| struct ContentView_Previews: PreviewProvider { | |
| static var previews: some View { | |
| ContentView() | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SwiftUI의 State와 Binding을 이해할 수 있도록, 가독성을 위해, 간략하게 한 파일로 작성했습니다.