We provide complete mobile and web apps development solutions

Tuesday, August 2, 2016

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*/

Semicolons:
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

Booleans:

let userActive = true

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

Optionals:
Swift handles the absence value with Optionals.


var userStr = String? = nil



import Cocoa

var userStr : String?=nil

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

}

0 coment�rios:

Post a Comment

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts