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 { | |
| var body: some View { | |
| /// add the image | |
| Image("background0") | |
| /// we make it fit the screen | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| } |
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 { | |
| /// The timer, which will update the background image. | |
| let timer = Timer.publish(every: 0.04, on: .main, in: .common).autoconnect() | |
| /// so we can keep track of the current image. | |
| /// the images are named: | |
| /// background<number> | |
| /// where number is from 0...21 (check out the Assets folder, 22 images in total) | |
| @State var currentImageNumber = 0 |
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 { | |
| /// true = green, false = blue | |
| /// because this is a `@State` property, any view (like the rectangle) that accesses it will update whenever this value changes, always keeping in sync | |
| @State var rectangleIsGreen = false | |
| var body: some View { | |
| VStack { | |
| RoundedRectangle(cornerRadius: 16) | |
| /// ternary operator: if `rectangleIsGreen` is true, the fill color should be green |
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
| # define the function | |
| def plural_check(string: str, count: int) -> str: | |
| # see if the count is plural | |
| if count != 1: | |
| # first check if it ends in "y" | |
| if string.endswith("y"): | |
| # if the second to last letter is a vowel, just add an "s" |
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 ColorView: View { | |
| @Binding var colorRectangleIsGreen: Bool | |
| var body: some View { | |
| RoundedRectangle(cornerRadius: 5) | |
| .fill(colorRectangleIsGreen ? Color.green : Color.blue) | |
| .frame(width: 100, height: 100) | |
| .padding() | |
| } | |
| } |
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 rectangleIsGreen = false | |
| var body: some View { | |
| HStack { | |
| RoundedRectangle(cornerRadius: 16) | |
| .fill(rectangleIsGreen ? Color.green : Color.blue) | |
| .frame(width: 250, height: 250) | |
| .padding() | |
| RoundedRectangle(cornerRadius: 16) |
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 ColorView: View { | |
| @Binding var colorRectangleIsGreen: Bool | |
| var body: some View { | |
| RoundedRectangle(cornerRadius: 16) | |
| .fill(colorRectangleIsGreen ? Color.green : Color.blue) | |
| .frame(width: 250, height: 250) | |
| .padding() | |
| } | |
| } | |
| struct ContentView: View { |
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 ColorView: View { | |
| @Binding var colorRectangleIsGreen: Bool | |
| var body: some View { | |
| RoundedRectangle(cornerRadius: 16) | |
| .fill(colorRectangleIsGreen ? Color.green : Color.blue) | |
| .frame(width: 250, height: 250) | |
| .padding() | |
| } | |
| } |
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 player that will play the audio. It can't be a local variable. | |
| /// Must have the `@State` attribute, because we need modify it later on | |
| @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 UIKit | |
| import SwiftUI | |
| // Auto-generated code | |
| class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
| var window: UIWindow? | |
| func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { |