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
| struct ContentView: View { | |
| @State var buttonPressed = false | |
| var body: some View { | |
| VStack { | |
| /// support for if-else introduced in Xcode 12 | |
| if buttonPressed { | |
| Text("Gas pedal pressed!") | |
| } else { |
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
| /// we can make the modifier more Swifter by wrapping it in a method... | |
| /// ... then making the method an extension of View, so we can easily add it to any SwiftUI view | |
| public extension View { | |
| func onTouchDownUpEvent(changeState: @escaping (ButtonState) -> Void) -> some View { | |
| modifier(TouchDownUpEventModifier(changeState: changeState)) | |
| } | |
| } |
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
| Text("Press to accelerate!") | |
| .foregroundColor(Color.white) | |
| .padding(10) | |
| .background(Color.gray) | |
| .cornerRadius(6) | |
| .padding(10) | |
| /// our brand-new, shiny view modifier! | |
| .onTouchDownUpEvent(changeState: { (buttonState) in | |
| if buttonState == .pressed { | |
| buttonPressed = true |
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
| import AVFoundation | |
| import SwiftUI | |
| import PlaygroundSupport | |
| struct SwiftUIAudioPlayerView: View { | |
| /// the audio player that will play your audio file. Can't be a local variable. | |
| /// Must be a `@State` property because we need to modify it later | |
| @State var audioPlayer: AVAudioPlayer? | |
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
| import AVFoundation | |
| import SwiftUI | |
| import PlaygroundSupport | |
| class UIKitAudioPlayerView: UIView { | |
| /// the audio player that will play your audio file. Can't be a local variable. | |
| var audioPlayer: AVAudioPlayer? | |
| /// so we only make and connect the button once |
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
| import SwiftUI | |
| class AppDelegate: NSObject, UIApplicationDelegate { | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { | |
| /// your push notification code goes here | |
| return true | |
| } | |
| } |
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
| @main | |
| struct HelloWorldApp: App { | |
| var body: some Scene { | |
| WindowGroup { | |
| ContentView() | |
| } | |
| } | |
| } | |
| struct ContentView: View { | |
| var body: some View { |