Swift programming language Tutorial


Intro

  • Swift is a multi-paradigm, compiled programming language created by Apple for iOS and OS X development.
  • Introduced at Apple's 2014 Worldwide Developers Conference (WWDC), Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products.
  • Swift is intended to be more resilient to erroneous code ("safer") than Objective-C, and also more concise.
  • It is built with the LLVM compiler framework included in Xcode 6, and uses the Objective-C runtime, allowing C, Objective-C, C++ and Swift code to run within a single program.

History

  • Development on Swift began in 2010 by Chris Lattner, with the eventual collaboration of many other programmers.
  • Swift took language ideas "from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list".
  • On June 2, 2014, the WWDC app became the first publicly released app written in Swift.
  • A beta version of the language was released to registered Apple developers at that time, but Apple did not promise that the final version of Swift will be source compatible with the version released.
  • Apple planned to make source code converters available if needed for the full release.

Key Points

  • Swift is a new programming language for iOS and OS X app development. Nonetheless, many parts of Swift will be familiar from your experience of developing in C and Objective-C.
  • Swift provides its own versions of all fundamental C and Objective-C types, including Int for integers, Double and Float for floating-point values, Bool for Boolean values, and String for textual data. Swift also provides powerful versions of the two primary collection types, Array and Dictionary, as described in Collection Types.
  • Like C, Swift uses variables to store and refer to values by an identifying name. Swift also makes extensive use of variables whose values cannot be changed. These are known as constants, and are much more powerful than constants in C. Constants are used throughout Swift to make code safer and clearer in intent when you work with values that do not need to change.
  • In addition to familiar types, Swift introduces advanced types not found in Objective-C, such as tuples. Tuples enable you to create and pass around groupings of values. You can use a tuple to return multiple values from a function as a single compound value.
  • Swift also introduces optional types, which handle the absence of a value. Optionals say either “there is a value, and it equals x” or “there isn’t a value at all”. Optionals are similar to using nil with pointers in Objective-C, but they work for any type, not just classes. Optionals are safer and more expressive than nil pointers in Objective-C and are at the heart of many of Swift’s most powerful features.
  • Optionals are an example of the fact that Swift is a type safe language. Swift helps you to be clear about the types of values your code can work with. If part of your code expects a String, type safety prevents you from passing it an Int by mistake. This restriction enables you to catch and fix errors as early as possible in the development process.

Useful Link

Comments

Post a Comment