Swift Basics

Swift is an Open Source, powerful language for mac OS, iOS.
Swift 3 is the major release developed at Swift.org.

Declaring Constants :

let maximumMembers = 5
var minimumMembers = 2
let pi = 3.1416

Type Annotations :

var username: String
username = "Srinivas Nidadavolu"
println(username) // prints Srinivas Nidadavolu

Constant value cannot be changed.

var username = "SRINIVAS NIDADAVOLU"
username = "KARUNA" // compile time error - username cannot be changed

Comments :

Comments in swift is similar to other programming languages like java, javascipt and c etc.

// for comment

/* this is also a comment*/

Swift doesnt need a semicolon (;) after every statement. Its optional. If your using multiple statements in the same line, then its required.

Data Types :

32 Bit and 64 bit platforms :

32 bit platform:

Int is Int32
UInt is UInt32

64 bit platform:

Int is Int64
UInt is UInt64


let userActive = true

if userActive{
println("user is active")
println("user is inactive")

Swift handles the absence value with Optionals.

var userStr = String? = nil

import Cocoa

var userStr : String?=nil

if  userStr!=nil {
println("It contains nil")



Popular posts from this blog

What is Android ?