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, Cpp and Swift code to run within a single program.
Syntax and Code Structure
Traditional first line code :
1 |
println("Hello, World") |
Variables And Constants
In swift language var is used to create variables, and let is used to create constants.
1 2 3 4 5 |
var variable = 10 variable = 25 let constant = 15 |
A constant or variable must have the same type as the value you want to assign to it. However, you don’t always have to write the type explicitly. Providing a value when you create a constant or a variable lets the compiler infer its type. In the above example, the compiler infers that “variable” is an integer because its initial value is an integer.
If