iOS Fundamentals — iOS Tour

Dipika Kansara
4 min readDec 9, 2021

In this tutorial you will learn basic iOS fundamentals like first program “Hello World”, Property declaration and Basic Data types.

The first program Hello, World! is often used to introduce a new programming language to start learn new language. Let’s explore how to create “Hello, World!” program in Swift.

print("Hello World!)

Now let’s jump on our first topic in Swift.

Topic 1 — Swift Comments:

Comments are hints that we can add to our program to make our code more understandable. They are meant for people reading the code. There are two types of Swift comments

  1. Single Line Comment:

We use two slashes // to write single line comments in Swift.

2. Multi — Line Comment:

We use We use /* at starting point and */ end point for multi line comments in Swift.

Topic 2 — Constants and Variables

  1. Variables:

A variable is a storage area to hold data. Here, number is a variable storing the value 50. In Swift, we use the var keyword to declare variables.

var number = 50

We can declare our variable with their particular data types using Annotation. For Example,

var number : Int = 50

Also, We can assign and change our declared variable. Because The var keyword in Swift allows you to create a mutable variable. A mutable variable can be set more than once.

var language : String = "Swift"// assigning a new value to language
language = "SWIFTUI"
print(language)

2. Constants:

A constant is a special type of variable whose value cannot be changed. Here, after a is initialised to 50, we cannot change its value. In Swift, we use the let keyword to declare variables.

let constantNumber = 50

We can declare our Constant with their particular data types using Annotation. For Example,

let constantNumber : Int = 50

Here We can not change Constant’s value same like Variables. Because, The let keyword in Swift allows you to create immutable variables. An immutable variable can be initialised only once and acts as a constant. For Example,

let constantNumber = 50
constantNumber = 10 // Error
print(constantNumber)
it will return error like error: cannot assign to value: ‘constantNumber’ is a ‘let’ constant

So Important Question is What is Difference between Let and Var?

Answer: A var can be changed once it is initialized. However, a let variable cannot be changed once it is initialized.

Topic — 3 Basic Data Types:

data types define as the type of data that can be stored inside a variable. For example,

var number : Int

Here, Int is a data type that specifies that the num variable can only store integer data.

There are six basic types of data types in Swift programming.

  1. Character :

The character data type is used to represent a single-character string. We use the Character keyword to create character-type variables. For example,

var letter  = "S"// Declare the variable with data type using Annotationvar letter : Character = "S"
print(letter)

2. String:

The String data type is used to represent a text data. We use the String keyword to create String variables. For example,

var language  = "Swift"// Declare the variable with data type using Annotationvar language : String = "Swift"
print(language)

3. Integer:

The Integer data type is used to represent a Whole Number with No fractional component. We use the Int keyword to create Integer variables. For example,

var Number  = 50// Declare the variable with data type using Annotationvar Number : Int = 50
print(Number)

4. Float:

The Float data type is used to represent a with fractional component. We use the Float keyword to create Float variables. For example,

var pi = 3.14// Declare the variable with data type using Annotationvar pi : Float = 3.14
print(pi)

5. Double:

The Double data type is also used to represent a with fractional component.However, Double supports data up to 15 decimal places. We use the Double keyword to create Double variables. For example,

var longitude = 27.67532// Declare the variable with data type using Annotationvar longitude : Double = 27.67532
print(longitude)

6. Bool:

The Bool data type is also used to represent a logic entities. It can have two values either True or False . We use the Bool keyword to create Bool variables. For example,

var testpass : Bool = trueprint(testpass) // truevar testfail : Bool = falseprint(testfail) // false

I have covered three topics here about iOS Basics. Also , I have mentioned youtube link below for better learning.

https://www.youtube.com/watch?v=yMYm_XcIsTg

Happy Coding 😁

--

--