swift是一个新的支持iOS,OS X开发的面向对象语言。他是时髦的、强大的、易用的。
let people = ["Anna": 67, "Beto": 8, "Jack": 33, "Sam": 25] for (name, age) in people { println("\(name) is \(age) years old.") }
安全:swift是类型安全的,他使用类型推断机制,限制对象指针使用、自动管理内存来使程序更安全,让开发人员更容易开发出安全稳定的软件。
func configureLabels(labels: UILabel[]) { let labelTextColor = UIColor.greenColor() for label in labels { // label inferred to be UILabel label.textColor = labelTextColor } }
时髦:swift具有optional,泛型,元祖等现代语言的特性。比objective-c语言更具灵感,更接近于自然语言,使代码可读性更好。
let cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"] let sortedCities = sort(cities) { $0 < $1 } if let indexOfLondon = find(sortedCities, "London") { println("London is city number \(indexOfLondon + 1) in the list") }
强大:使用swift中强大的模式匹配特性写出更简单,更直观表意的代码。通过变量插值的方式来方便的格式化字符串;方便的使用Foundation and UIKit
let size = (20, 40) switch size { case let (width, height) where width == height: println("square with sides \(width)") case (1..10, 1..10): println("small rectangle") case let (width, height): println("rectangle with width \(width) and height \(height)") }
交互性:使用playgrounds 来试验新技术,分析问题,做所见即所得的界面原型
高效: Swift的编译器使用高级的代码分析功能来调优你的代码。让你更专注于开发应用,而不必在性能优化上投入大量的精力。
翻译自:https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html