Swift Variables



Swift Programming Language By Knownion


Variables are used to store data in memory so that we can use them in program. Variables are like container that can hold data which can be changed later. Every variable has a unique name called identifier.

Variable Declaration In Swift?


A variable declaration tells the compiler of which type, where and how much to create the storage for the variable. Declarations of variables are made using the var keyword.

Example

import Cocoa
var firstvar = 68
println(firstvar)

Output
68

Type Annotations


Programmers can supply a type annotation when they declare a variable, to be clear about the kind of value(s) that the declared variable can store. The general form of using this variable is:

Syntax

var variableName:<data type> = <optional initial value>

Example

import Cocoa
var firstvar = 68
println (firstvar)
var secVar:Float
secVar = 3.14159
println (secVar)
println(" 1st Value \(varA) 2nd Value \(varB) ")



Post a Comment