Tuesday, 28 April 2015

Defining Constants And Variables In Swift

Syntax

 var <variablename>
 let  <constantname>

or

var <variablename>: datatype
let <constantname>: datatype

Examples

var variable
let constant

or
var stringVariable: String
let  constantString: String

Assigning values

variable=2
constant="Hello World"  // value can not change.


stringVariable="Hello World"
constantString="Hello World"

Explanation
   
   The above examples show the var keyword is used declare variables and the let keyword is used to declare constant.we can declare variable or constant with data type or without data type. When we declare constant or variable without data type, the appropriate type of the variable or constant is defined when value is assigned to it.
Note
   1. The above examples show (;) not needed in end of the statement
   2. The value can be assigned at declaration itself.
   3. If once the value for constant assigned, can not be changed.


 

Monday, 27 April 2015

Setting Up Your Environment For Swift

 
1. You need Xcode 6.1 or later to develop with the iOS 8.1 SDK. Xcode 6.1  or  later requires Mac

OS X 10.9.4 (Mavericks) or later according to the App Store. The aforementioned Downloads page

confirms that it requires Mavericks or Yosemite.

If you want to develop using the iOS 8.0 SDK, you need Xcode 6.0 or later. It requires Mavericks, too.

2. A paid iOS developer account.

3. You should have at least an iPhone/ iPad/ iPod touch.

Introduction To Swift Programming Language


Swift is a multi-paradigm, compiled programming language created by Apple Inc. for iOS , OS X and OS Watch 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.