Day 1 of 100 days of Swift:

During my first day of the Swift course, offered by HWS.

I covered the following:

  • Constants and variable
  • Strings
  • Number (Int & Double)

Few notes here and there

/// Constant is used when you don't want the value of a data  to change
e.g
let nameOfSchool = "Loop N Academy"

/// Variable is used when you want the value of a data to change. 
example:

var nameOfPet = "Duffypion"

Note: Trying to change the value of a constant after being declared will cause swift to show a warning.

String

The String is basically a text assigned to a constant or variable. example:

var name = "Opeyemi"
let cityName = "Lagos"

When you have a text on a single line, you surround the text with double quote, like so "Opeyemi". However, when you have multiline text you surround the text with triple quotes. example:

var longText = """ 
Once upon a time, in a faraway land, there
lives an old orange, famously known for dancing on the 
tree.
"""

Note: The triple must be on separate single line.

Number

Whole number (Integer)

Similar to strings integers can be created by using either var(variable) or let(constant)

And arithmetic operations can also be run on integers. example:

let a = 2 + 1
print(a)

//output -> 3

Decimal (Double)

Double are numbers with decimal point example :

let pi = 3.1429272

Arithmetic operations can also be carried out on Double;

let addValue = 1.0 + 0.2
print(addValue)

//output -> 1.2

NOTE: Swift won't allow data of different types to mix together, it's referred to as type safety.

Thank you for reading my swift journal.