Swift (programming language)

from Wikipedia, the free encyclopedia
Swift
logo
Basic data
Paradigms : Multiparadigms ( object-oriented , functional , imperative , block structure )
Publishing year: 2014
Designer: Chris Lattner
Developer: Apple Inc.
Current  version : 5.2   (March 24, 2020)
Typing : strong , static
Influenced by: Objective-C , Rust , Haskell , Ruby , Python , C # , CLU , D
Operating system : macOS , iOS (incl. tvOS , watchOS ), Linux
License : Apache license 2.0 (since Swift 2.2)
https://swift.org/

Swift is a programming language from Apple Inc. for iOS , iPadOS , macOS , tvOS , watchOS and Linux .

It's a multi-paradigmatic language that takes ideas from Objective-C , Rust , Haskell , Ruby , Python , C # , CLU, D, and other programming languages. It offers mechanisms such as classes , inheritance , closures , type inference , higher-order functions , generic types and namespaces as well as multiple return types and values. The compiler is based on LLVM .

According to Swift's chief architect, Chris Lattner, Swift is not intended to replace Objective-C at Apple, but rather to offer an additional option for development for the iOS and macOS platforms .

history

The development of Swift began in July 2010 by Chris Lattner , from the end of 2011 a larger development team worked on it. An update to the WWDC app released on June 2, 2014 was the first published application to be written in Swift. Swift was introduced to the general public for the first time at the WWDC 2014 developer conference . The corresponding manual was announced at the conference and made available in the iBooks Store .

Swift 1

Swift 1.0 was released by Apple on September 9, 2014. On this day the Golden Master of Swift 1 including Xcode 6.1 was distributed.

Swift 2

At WWDC 2015 on June 8, 2015, Apple introduced Swift 2.0. In addition to various linguistic extensions such as exception handling using try, throwand it catchwas also announced that the Swift license will be changed to an OSI-compliant open source license. On December 3, 2015, Apple then placed Swift under the Apache 2.0 license, which enables Swift to be used freely (also for commercial projects). Apple released the source code in a GitHub repository and also offers a port for Linux .

The last version of Swift 2 is Swift 2.3 and was released with Xcode 8.

Swift 3

At WWDC 2016, Swift 3.0 was introduced together with iOS 10.0. Swift 3 is the first major release since Apple made Swift open source. Due to some profound changes, Swift 3 is no longer source code compatible with previous versions. The main reason for this is the new API design guidelines, which form the basis for the further development of Swift and for which clarity or clarity should be particularly important.

The list of new features and changes in Swift 3.0 comprises more than 100 points. Apple has published a migration guide to help you transition. As of Xcode 8.0, there is a “code migrator” for adapting existing code, which is intended to automate a large number of the changes required.

Swift 4

In September 2017, the next major version was released with Swift 4. New functions include improved collection types and easier handling of strings. In order to be able to continue to use existing Swift 3 code, the compiler has a Swift 3 and Swift 4 mode, which can also be used together in a project.

Swift 5

Version 5.0, which was published on March 25, 2019, brought some changes and improvements, including in the standard library and the package manager. The change from UTF-16 to UTF-8 encoding as the standard for the string data type should also be emphasized .

Swift 5.1 was released on September 20, 2019.

The current version, Swift 5.2, was released on March 24, 2020. Added functionality includes property wrappers and opaque types, among others.

Code examples

// variables
var implicitInteger = 70
var implicitDouble = 70.0
var explicitDouble: Double = 70.0

// constants
let apples = 3
let oranges = 5
let appleSummary = "Ich habe \(apples) Äpfel."
let fruitSummary = "Ich habe \(apples + oranges) Früchte."

print("Hallo Welt!")

// loops
let people = ["Anna": 67, "Julia": 8, "Hans": 33, "Peter": 25]
for (name, age) in people {
    print("\(name) ist \(age) Jahre alt.")
}

// functions (aka "named closures")
func sayHelloTo(yourName name: String) -> Void {
    print("Hello \(name)")
}

sayHelloTo(yourName : "Otto")

// multiline preformatted text
let text  = """
Hello Otto,

why don't you take a break?
"""

See also

literature

Web links

Individual evidence

  1. Swift.org - Download Swift! Apple Inc., accessed March 30, 2020 .
  2. a b c d Chris Lattner: Chris Lattner's Homepage. Retrieved June 3, 2014 : “… it also greatly benefited from the experiences hard-won by many other languages ​​in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C #, CLU, and far too many others to list. "
  3. a b Building assert () in Swift, Part 2: __FILE__ and __LINE__ - Swift Blog -. Apple Developer, accessed September 26, 2014 : "Swift borrows a clever feature from the D language : these identifiers expand to the location of the caller when evaluated in a default argument list."
  4. ^ Nathan Ingraham: Apple has a new programming language called Swift, 'and it totally rules'. The Verge , accessed June 2, 2014 .
  5. ^ Owen Williams: Apple announces Swift, a new programming language for iOS. The Next Web, Inc., accessed June 2, 2014 .
  6. Xcode-users mailing list. Apple Inc., accessed June 5, 2014 .
  7. ^ Platforms State of the Union. Session 102 at WWDC 2014 at approx. 30 min.
  8. ^ The Swift Programming Language. Apple Inc., accessed June 2, 2014 .
  9. ^ Apple Inc .: Swift Has Reached 1.0 - Swift Blog. Retrieved January 7, 2018 (American English).
  10. Swift 2.0
  11. The Swift Linux Port
  12. API design guidelines
  13. Migrating to Swift 2.3 or Swift 3 from Swift 2.2
  14. Apple Inc .: Swift 4.0 Released! In: Swift.org . September 19, 2017 ( swift.org [accessed October 6, 2017]).
  15. Swift 5 Released! Apple Inc., accessed April 13, 2019 .
  16. UTF-8 string. Apple Inc., accessed March 30, 2020 .
  17. Swift 5.1 Released! Apple Inc., accessed March 30, 2020 .
  18. Swift 5.2 Released! Apple Inc., accessed March 30, 2020 .
  19. Properties. Apple Inc., accessed March 30, 2020 .
  20. Opaque Types. Apple Inc., accessed March 30, 2020 .