how to declare variable in swift language
How to declare the variable in swift language
the variable is very importation in any type of language. Swift language is supported by the two type of variable var and let. Var is used to change the value and let is use not change the value (let is constant variable). Every variable declared in two-way. watch this video for more understanding.
Step - 1
First open your Xcode
Step - 2
Select create a new Playground project
if don't know how to create playground visited this line
Step - 3
write your code in the playground
syntax:-
(var type) variablename = values
two way to create a var variables
string
var name = "parth" // first way
var myname:String = "parth" // second way
Integer
var integer = 100
var myinteger:Int = 100
Float
var float = 10.1
var myfloat:Float = 10.1
boolean
var bool = true
var mybool:Bool = true
let is use not change the value (let is constant variable).
same two way to create a let variables
string
let letname = "parth" // first way
let myletname:String = "parth" // second way
Integer
let letinteger = 100
let myletinteger:Int = 100
Float
let letfloat = 10.1
let myletfloat:Float = 10.1
boolean
let letbool = true
let myletbool:Bool = true
how to append a variable in swift language
// string
var appendstring = "parth"
appendstring += "hardik"
var myappendstring:String = "parth"
myappendstring += "hardik"
// integer
var appendinteger = 100
appendinteger += 100 // append variable
appendinteger -= 10 // remove value
var myappendinteger:Int = 100
myappendinteger += 100
// float
var appendfloat = 10.1
appendfloat += 10.1
appendfloat -= 5.5
var myappendfloat:Float = 10.1
myappendfloat += 10.1
myappendfloat -= 5.5
// boolean
var appendbool = true
appendbool = false // your not use binary operator
var myappendbool:Bool = true
myappendbool = false // your not use binary operator
// let variable is not append and remove because let is constant (not change values)
let letappend = 100
letappend += 100 //ERROE
SEE MY PLAYGROUND SCREENSORT:
if you are more understanding about variable open this line
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment