Skip to content

Instantly share code, notes, and snippets.

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
@IBAction func temperatureSwitchToggled(_ sender: Any) {
temperatureSwitchIsOn = temperatureSwitch.isOn
personIsBoris = !temperatureSwitch.isOn
...
}
@IBAction func temperatureSwitchToggled(_ sender: Any) {
temperatureSwitchIsOn = temperatureSwitch.isOn
personIsTrump = temperatureSwitch.isOn
...
if personIsTrump {
personImageView.image = trumpImage
} else {
personImageView.image = borisImage
enum LoginStatus {
case guest
case failedLogin
case loggedIn
case sessionExpired
}
var loginStatus = LoginStatus.loggedIn
/// 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)
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.
/// 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)
/// 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
# 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")