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
| let trumpImage = UIImage(named: "trump") | |
| let borisImage = UIImage(named: "boris") | |
| var personIsBoris = true | |
| @IBOutlet weak var personImageView: UIImageView! | |
| @IBOutlet weak var temperatureLabel: UILabel! | |
| /// off = Celsius, on = Fahrenheit | |
| var temperatureSwitchIsOn = 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
| @IBAction func temperatureSwitchToggled(_ sender: Any) { | |
| temperatureSwitchIsOn = temperatureSwitch.isOn | |
| personIsBoris = !temperatureSwitch.isOn | |
| ... | |
| } |
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
| @IBAction func temperatureSwitchToggled(_ sender: Any) { | |
| temperatureSwitchIsOn = temperatureSwitch.isOn | |
| personIsTrump = temperatureSwitch.isOn | |
| ... | |
| if personIsTrump { | |
| personImageView.image = trumpImage | |
| } else { | |
| personImageView.image = borisImage |
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
| enum LoginStatus { | |
| case guest | |
| case failedLogin | |
| case loggedIn | |
| case sessionExpired | |
| } | |
| var loginStatus = LoginStatus.loggedIn |
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
| /// an enum is more readable than true/false | |
| public enum ButtonState { | |
| case pressed | |
| case notPressed | |
| } | |
| /// ViewModifier allows us to get a view, then modify it and return it with modifications | |
| public struct TouchDownUpEventModifier: ViewModifier { | |
| /// Later, .onChanged will be called multiple times (around 10 times a second once your finger touches down) |
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 | |
| struct ContentView: View { | |
| /// we need to keep track of the state of the timer | |
| /// if it's currently active, the button should say "Stop" and stop the timer when pressed | |
| /// if it's not currently active, the button should say "Start" and start the timer when pressed | |
| @State var timerActive = true | |
| /// The timer. Will update the background image. |
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
| sdf |
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
| /// the UIImageView that will hold the animation | |
| let imageView = UIImageView() | |
| imageView.frame = CGRect(x: 100, y: 100, width: 150, height: 150) | |
| view.addSubview(imageView) | |
| /// the images that will be animated | |
| /// images are stored in the Resources folder of this playground | |
| let imagesToAnimate = [UIImage(named: "0")!, UIImage(named: "1")!, UIImage(named: "2")!] | |
| let animationImages = UIImage.animatedImage(with: imagesToAnimate, duration: 1) |
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
| /// the UIImageView that will hold the animation | |
| let imageView = UIImageView() | |
| imageView.frame = CGRect(x: 100, y: 100, width: 150, height: 150) | |
| view.addSubview(imageView) | |
| /// the images that will be animated | |
| /// images are stored in the Resources folder of this playground | |
| let imagesToAnimate = [UIImage(named: "0")!, UIImage(named: "1")!, UIImage(named: "2")!] | |
| imageView.animationImages = imagesToAnimate |
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 match_number(number, singular, plural): | |
| if number == 1: | |
| return str(number) + " " + singular # return the number + the singular noun | |
| else: | |
| return str(number) + " " + plural # return the number + the plural noun | |
| followers_count = 1 | |
| grammarized_followers = match_number(number = followers_count, singular = "follower", plural = "followers") |