Swift: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 1: | Line 1: | ||
<source lang="bash"> | <source lang="bash"> | ||
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}" | export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}" | ||
</source> | |||
==Hello World== | |||
<source lang="swift"> | |||
import UIKit | |||
class ViewController: UIViewController { | |||
@IBOutlet weak var nameTexField: UITextField! | |||
@IBOutlet weak var ageTextField: UITextField! | |||
@IBOutlet weak var helloLabel: UILabel! | |||
override func viewDidLoad() { | |||
super.viewDidLoad() | |||
} | |||
@IBAction func clickMeAction(_ sender: Any) { | |||
print("Hello \(nameTexField.text!)"); | |||
helloLabel.text = "Hello \(nameTexField.text!), your age is \(ageTextField.text!)"; | |||
} | |||
} | |||
</source> | </source> | ||
Revision as of 23:21, 7 April 2019
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
Hello World
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var nameTexField: UITextField!
@IBOutlet weak var ageTextField: UITextField!
@IBOutlet weak var helloLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func clickMeAction(_ sender: Any) {
print("Hello \(nameTexField.text!)");
helloLabel.text = "Hello \(nameTexField.text!), your age is \(ageTextField.text!)";
}
}
Features
- Closures unified with function pointers
- Tuples and multiple return values
- Generics
- Fast and concise iteration over a range or collection
- Structs that support methods, extensions, and protocols
- Functional programming patterns, e.g., map and filter
- Powerful error handling built-in
- Advanced control flow with do, guard, defer, and repeat keywords