Numbers

#numberformat #integer

Overview

As default, Int reflects the system bit size;

  • If system is 32 bit Int works as In32

  • if system is 64bit Int works as Int64

Additionally, you can choose whatever type of Int (Int16, Int32, Int64).

Things to learn

Integer Types

Integer 16/32/64 are not interchangable. Once you defined the format you cannot change it afterwards. Because each one needs different space. If you define all as integer 64 you will end up with much space than you need and that will increase you file size thus makes the app work slower.

Integer 16

Integer 32

Integer 64

Notes

  • String + String = Concatenation

  • Number + Number = Addition

  • Decimal Numbers = Double

Sample Codes

let a = 3.1  // print: 3.1
let b = 3.0  // print: 3  // since it is equal to 3 swift sees it as an integer
let b = 3 // print: 3
Changes string and decimal to integer
let a = "1"  // print: "1"
let b = Int(a)  // print: 1

Sources

Videos

Articles / Documents

Last updated