One can represent numbers using swift just creating a variable. variables, numbers and data type is essential in every programming language. Swift  automatically detects which type of Variable it is. If you want to mention the variable type just add : after the variable name and then mention the type.

Variable is a container to keep data. Data type can be Integer, Double, Float, Boolean type.

Integer can be of 2 types.

One is bit-wise Signed, eg. Int8, Int16, Int32, Int64

and another one is bit-wise Unsigned, eg. UInt8, UInt16, UInt32, UInt64

We can concat or print some variables inside a Sting using String Interpolation ( \ – backslash ).

Check out the examples for some demonstration

//: Playground - noun: a place where people can play

import UIKit

// Number Practice 

var age = 28

//expicitly devleared type 

var weight:Int = 76

var salary:UInt64 = 20000

var s = 50.0

var s: Double = 20.0

var t = true

var f = False

// Arithmetic Operators 
/*
    + - / *
 */

var area = 15*10 // 150

var sum = 5+5 // 10
 
var diff = 10-3 //07

var div = 10/3 // 3 

var remainder = 16 % 5 // 1

print ("The result of sum 5+5 =\(sum),
        diff 10-3 = \(diff) , div 10/3 = \(div)
        and remiander 10/3 = \(remainder)")


var randomnumber = 50

if randomnumber % 3 == 0 {
    print("is enven")
}else{
    print("is Odd")
}

These are simple examples for Variables and Data types. Swift 3 documentation is one of the best documentation I have read so far. For further just go through the doc.

riashad

riashad

love coding, freelancer, love to travel and ride bikes