Swift Language

Apple's new language for writing MacOsx and iOS apps.

http://developer.apple.com/swift/

http://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html

Modern

Swift is the result of the latest research on programming languages, combined with decades of experience building Apple platforms. Named parameters brought forward from Objective-C are expressed in a clean syntax that makes APIs in Swift even easier to read and maintain. Inferred types make code cleaner and less prone to mistakes, while modules eliminate headers and provide namespaces. Memory is managed automatically, and you don’t even need to type semi-colons.

Code

Swift has many other features to make your code more expressive:

Here is what it looks like:

 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)") }


CategoryProgrammingLanguage


EditText of this page (last edited October 4, 2014) or FindPage with title or text search