Swift is a powerful and intuitive programming language for macOS, iOS, watchOS, tvOS, and beyond. It is designed to give developers the freedom and capabilities they need to create a variety of apps. Swift is easy to learn and use, and provides a safe and fast way to develop powerful apps.
An example of a program written in Swift is a simple calculator app. Here is a code snippet for a basic calculator:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var resultLabel: UILabel!
var numberOnScreen:Double = 0
@IBAction func numbers(_ sender: UIButton) {
if let number = sender.currentTitle {
if number == “C” {
resultLabel.text = “0”
numberOnScreen = 0
} else {
if resultLabel.text == “0” {
resultLabel.text = number
} else {
resultLabel.text = resultLabel.text! + number
}
numberOnScreen = Double(resultLabel.text!)!
}
}
}
}
This code snippet creates a basic calculator app that allows the user to input numbers and perform basic calculations.