3. Class Rules
● Mutual Respect and Discipline
● Use mobiles when advised by course
incharge
● Silence is golden as it will help to
understand concepts well
● Maintain a book to note down all
important points and for assignments
● Be on time and notify for absence
4. Overview
Three key components in each lesson will guide your learning:
● Learn. A list of learning goals for that lesson
● Do. Hands-on practice with activities from the curriculum
● Reflect. Opportunities to design a personal project and plan
for the classroom
Instagram: @meetshehrevar
5. 1. Xcode Setup
● Xcode is what is known as an integrated development environment or IDE for
short.
● If you don’t get this welcome
dialogue, then you can
always go up to the
“File” menu, go under “New,”
and then choose “Playground.”
Instagram: @meetshehrevar
6. Click on “Get started with a playground.” The dialog that pops up
allows you to choose what type of playground you want to create.
Instagram: @meetshehrevar
7. For the purposes of this course choose “Blank” under “iOS.”
You can save your playground anywhere you want. Make sure you remember
where you save it so you can easily access it.
Instagram: @meetshehrevar
8. Different Elements of the Playground
1. Code editor – this is where you’re going to be typing your Swift code.
2. Line numbers – these will help you
refer to different lines of code.
3. Status bar – tells you the current
status of the playground.
4. Show/Hide Debug – allows you to
hide or show the debug or console
area
5. Execute Playground – runs all the
code in your playground
Instagram: @meetshehrevar
9. Swift Variables
Consectetur nec labore Adipiscing elit sed Sed eiusmod
declare a variable called stockPrice and set it equal to the number 100
var stockPrice = 100
Instagram: @meetshehrevar
10. 0
2
Swift Constants
A constant is a special type of variable whose value cannot be changed.
In Swift, we use the let keyword to declare constants. The value of a constant cannot be
changed.
For example,
let x = 5
x = 10 // Error
print(x)
main.swift:4:1: error: cannot assign to value: 'x' is a 'let' constant
Instagram: @meetshehrevar
12. Examples
// create character type variable
var letter: Character = "s"
print(letter)
// Output: s
Note: If you try to assign more than one character like "abc" to variables of
Character type, you'll get an error message.
Instagram: @meetshehrevar
13. // create string type variable
var language: String = "swift"
print(language)
// Output: swift
// create integer type variable
var number: Int = 3
print(number)
// Output: 3
● Size: Depends on the platform type
● Range: -231 to 231-1 (32 bit platform)
-263 to 263-1 (64-bit platform)
Instagram: @meetshehrevar
14. // create boolean type variable
let passCheck: Bool = true
print(passCheck)
let failCheck: Bool = false
print(failCheck)
If we don't assign any value to a boolean
variable, it takes false as its default value.
// create float type variable
let piValue: Float = 3.14
print(piValue)
// Output: 3.14
● Size: 32-bit floating-point number
● Range: 1.2 x 10-38 to 3.4 x 1038 (Up to
6 decimal places)
Instagram: @meetshehrevar
15. // create double type variable
let latitude: Double = 27.7007697012432
print(latitude)
// Output: 27.7007697012432
● Size: 64-bit floating-point number
● Range: 2.3 x 10-308 to 1.7 x 10308
(Up to 15 decimal places)
Note: If we have a number like 27.7007697012432, we use:
● Double to store the number with more precision (up to 15 decimal places)
● Float to store the number with less precision (up to 6 decimal places)
Instagram: @meetshehrevar