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.") }
func configureLabels(labels: UILabel[]) { let labelTextColor = UIColor.greenColor() for label in labels { // label inferred to be UILabel label.textColor = labelTextColor } }
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") }
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)") }
翻译自:https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html