SlideShare a Scribd company logo
SWIFT Programming basics
Contents
 Variables
 Constants
 Using print statement
 Data Types
 Operators
Kanika Sharma
2
Variables
 variables are used to store data in memory which can be used
throughout the program.
 Each variable must be given a unique name called identifier.
 In Swift, we use var keyword to declare a variable
Kanika Sharma
3
Assigning values to variables
 At the time of declaration
 Var name = “MCA”
 Later on in the program but using type annotation
var name : String
name=“mca”
OR
var name : String = “MCA”
Kanika Sharma
4
Constants
 In Swift, we use let keyword to declare a variable
Kanika Sharma
5
Literal
 A literal is a value that appears directly in your source code.
 It can be a number, character, or a string etc. For e.g: "Hello, World" , 12,
23.0, "C" are simple example of literals.
 Literals are often used to initialize (assign values to) variables or constants.
Kanika Sharma
6
Types of Literal
 Integer Literal
 Binary Literals
 Represents binary value.
 Begins with 0b.
 Octal Literals
 Represents octal value.
 Begins with 0o.
 Hexadecimal Literals
 Represents hexadecimal value.
 Begins with 0x.
 Decimal Literals
 Represents decimal value.
 Begins with nothing. Everything you declare in integer literal is of type decimal.
Kanika Sharma
7
Types of Literal
 String Literal
 Character Literal
 Decimal
 Boolean
Kanika Sharma
8
Best practices for naming Variable &
Constants
 Choose a name that makes sense. For example, var name makes more sense
than var n.
 Use camelCase notation to declare a variable or a constant. Camel-case
notation starts with lowercase letter.
 You can also define variables and constants without labeling it. Not labeling
with name means you are not going to use it in the program.
 Use constants if you only need to set a value once and never need to change
it again during a program. However, if you do need to change it at a later
point, use variables.
 Constant and variable names cannot contain whitespace characters,
mathematical symbols, arrows, private-use (or invalid) Unicode code points, or
line- and box-drawing characters. Nor can they begin with a number,
although numbers may be included elsewhere within the name.
Kanika Sharma
9
Using print statement
 Printing to the screen using simple print() function
 Print(“hello”)
 Printing constants, variables and literals
 Print(45)
 Printing without a link break using terminator parameter
 print("Hello”, terminator: " ")
 print(“MCA")
 print(“Welcome")
Kanika Sharma
10
Using print statement
 Printing multiple items using single print function
 print(“Welcome to", 2020, “MCA", separator: " ")
 Printing multiple lines
 print("Hello, rMCA")
 Printing multiple lines using triple quotes
 print("""
 Hello,
 MCA
 """)
Kanika Sharma
11
Using print statement
 Printing variables using string interpolation
var a = 10
var b = 20
var c = a + b
print("sum of (a) and (b) is",c)
Kanika Sharma
12
Example on print
var a = 10print(a) // Value
print(111) //Literal
print("Welcome",terminator:" ")
print("MCA")
print("Bye")
print("welcome","MCA","in",2020, separator:" .")
print("Hello rMCA")
print(""“
I
Am
SWIFT
""")
Kanika Sharma
13
Data Types
 Swift offers a collection of built-in data types which are string, integer,
floating-point numbers, and Booleans.
Kanika Sharma
14
Integers(Int)
 Integers (Int) are whole numbers.
 Variable/Constant declared of integer type can store whole numbers both positive and
negative including zero with no fractional components .
 Default Value: 0
 Size: 32/64 bit depends on the platform type.
 Range: -2,147,483,648 to 2,147,483,647 (32 bit platform)
 -9223372036854775808 to 9223372036854775807 (64 bit platform
 There are many variants of Integer type.e.g. UInt, Int8, Int16 etc. The most common one you use
is of Int.
 If you have a requirement to specify the size/type of integer a variable/constant can hold, you
can store it more specifically using UInt, Int8, Int16 etc.
Kanika Sharma
15
Integers(Int8)
 Int8
 Variant of Integer type that can store both positive and negative small
numbers.
 Default Value: 0
 Size: 8 bit
 Range: -128 to 127
 You can also find out the highest and lowest value a type can store using
.min and .max .
Kanika Sharma
16
Integers(Uint)
 Variant of Integer type called UInt (Unsigned Integer) which can only store
unsigned numbers (positive or zero).
 Default Value: 0
 Size: 32/64 bit depends on the platform type.
 Range: 0 to 4294967295 (32 bit platform)
 0 to 18446744073709551615 (64 bit platform)
Kanika Sharma
17
Floating Point (Float)
 Variables or Constants declared of float type can store number with
decimal or fraction points.
 Floating-point numbers are numbers with a fractional component, such as
4.993, 0.5, and −234.99.
 Default Value: 0.0
 Size: 32 bit floating point number.
 Range: 1.2*10-38 to 3.4 * 1038 (~6 digits)
Kanika Sharma
18
Floating Point (Double)
 Variables / Constants declared of Double type also stores number with
decimal or fraction points as Float but larger decimal points than Float
supports.
 Default value : 0.0
 Size: 64-bit floating point number. (Therefore, a variable of type Double can
store number with decimal or fraction points larger than Float supports)
 Range: 2.3*10-308 to 1.7*10308 (~15 digits)
Kanika Sharma
19
Boolean(Bool)
 Booleans (bools) are referred to as logical because they can either be
true or false.
 Variable/Constant declared of Bool type can store only two values either
true or false.
 Use Booleans when you need to determine whether some logic is true or
false.
 Default Value: false
Kanika Sharma
20
Character
 Variables/Constants declared of Character type can store a single-
character string literal.
 You can include emoji or languages other than english as an character in
Swift using escape sequence u{n} (unicode code point ,n is in
hexadecimal)
Kanika Sharma
21
String
 Variables or Constants declared of String type can store collection of characters.
 Default Value: "" (Empty String)
 It is Value type.
 You can use for-in loop to iterate over a string.
 Swift also supports a few special escape sequences to use them in string. For example,
 0 (null character),
  (a plain backslash ),
 t (a tab character),
 v (a vertical tab),
 r (carriage return),
 " (double quote),
 ' (single quote), and
 u{n} (unicode code point ,n is in hexadecimal).
Kanika Sharma
22
Comments
 Comments are a great way to create notes or reminders to yourself. When
you comment code, it means that it will not execute when your code
runs. There are two types of comments used: // or /* */. // is used for a
one-line comment and /**/ is used for a block of text.
Kanika Sharma
23
Ad

More Related Content

What's hot (20)

Java applets
Java appletsJava applets
Java applets
Khan Mac-arther
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
RaginiJain21
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
Type casting
Type castingType casting
Type casting
Ruchika Sinha
 
Class 10
Class 10Class 10
Class 10
SIVASHANKARIRAJAN
 
Identifier
IdentifierIdentifier
Identifier
ASHUTOSH TRIVEDI
 
Data structure array
Data structure  arrayData structure  array
Data structure array
MajidHamidAli
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Hossam Ghareeb
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Java calendar
Java calendarJava calendar
Java calendar
Yallappa Gadadi
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
Vladislav sidlyarevich
 
Python Notes.pdf
Python Notes.pdfPython Notes.pdf
Python Notes.pdf
sunithareddy78
 
Abstract class
Abstract classAbstract class
Abstract class
Tony Nguyen
 
Exception handling
Exception handlingException handling
Exception handling
Pranali Chaudhari
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
PhD Research Scholar
 
Python iteration
Python iterationPython iteration
Python iteration
dietbuddha
 
String Handling
String HandlingString Handling
String Handling
Bharat17485
 
Java Strings
Java StringsJava Strings
Java Strings
RaBiya Chaudhry
 

Similar to Variables and data types IN SWIFT (20)

Lesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptxLesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
Data type
Data typeData type
Data type
Isha Aggarwal
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
simranjotsingh2908
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docxINPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
jaggernaoma
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
Mohit Saini
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
madhurij54
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
Bussines man badhrinadh
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
C Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdfC Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
Unit Kediaman Luar Kampus
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
Madhavendra Dutt
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Mohamed Zain Allam
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptxPPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
Lesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptxLesson 4 Basic Programming Constructs.pptx
Lesson 4 Basic Programming Constructs.pptx
John Burca
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docxINPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
jaggernaoma
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
Mohit Saini
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
madhurij54
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
C Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdfC Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptxPPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
Ad

More from LOVELY PROFESSIONAL UNIVERSITY (19)

Enumerations, structure and class IN SWIFT
Enumerations, structure and class IN SWIFTEnumerations, structure and class IN SWIFT
Enumerations, structure and class IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Dictionaries IN SWIFT
Dictionaries IN SWIFTDictionaries IN SWIFT
Dictionaries IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Control structures IN SWIFT
Control structures IN SWIFTControl structures IN SWIFT
Control structures IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Arrays and its properties IN SWIFT
Arrays and its properties IN SWIFTArrays and its properties IN SWIFT
Arrays and its properties IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Array and its functionsI SWIFT
Array and its functionsI SWIFTArray and its functionsI SWIFT
Array and its functionsI SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
practice problems on array IN SWIFT
practice problems on array IN SWIFTpractice problems on array IN SWIFT
practice problems on array IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
practice problems on array IN SWIFT
practice problems on array  IN SWIFTpractice problems on array  IN SWIFT
practice problems on array IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
practice problems on array IN SWIFT
practice problems on array IN SWIFTpractice problems on array IN SWIFT
practice problems on array IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
practice problems on functions IN SWIFT
practice problems on functions IN SWIFTpractice problems on functions IN SWIFT
practice problems on functions IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
Soft skills. pptx
Soft skills. pptxSoft skills. pptx
Soft skills. pptx
LOVELY PROFESSIONAL UNIVERSITY
 
JAVA
JAVAJAVA
JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
Unit 5
Unit 5Unit 5
Unit 5
LOVELY PROFESSIONAL UNIVERSITY
 
Unit 4
Unit 4Unit 4
Unit 4
LOVELY PROFESSIONAL UNIVERSITY
 
Unit 3
Unit 3Unit 3
Unit 3
LOVELY PROFESSIONAL UNIVERSITY
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
Unit 1
Unit 1Unit 1
Unit 1
LOVELY PROFESSIONAL UNIVERSITY
 
COMPLETE CORE JAVA
COMPLETE CORE JAVACOMPLETE CORE JAVA
COMPLETE CORE JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
Data wrangling IN R LANGUAGE
Data wrangling IN R LANGUAGEData wrangling IN R LANGUAGE
Data wrangling IN R LANGUAGE
LOVELY PROFESSIONAL UNIVERSITY
 
Ad

Recently uploaded (20)

Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 

Variables and data types IN SWIFT

  • 2. Contents  Variables  Constants  Using print statement  Data Types  Operators Kanika Sharma 2
  • 3. Variables  variables are used to store data in memory which can be used throughout the program.  Each variable must be given a unique name called identifier.  In Swift, we use var keyword to declare a variable Kanika Sharma 3
  • 4. Assigning values to variables  At the time of declaration  Var name = “MCA”  Later on in the program but using type annotation var name : String name=“mca” OR var name : String = “MCA” Kanika Sharma 4
  • 5. Constants  In Swift, we use let keyword to declare a variable Kanika Sharma 5
  • 6. Literal  A literal is a value that appears directly in your source code.  It can be a number, character, or a string etc. For e.g: "Hello, World" , 12, 23.0, "C" are simple example of literals.  Literals are often used to initialize (assign values to) variables or constants. Kanika Sharma 6
  • 7. Types of Literal  Integer Literal  Binary Literals  Represents binary value.  Begins with 0b.  Octal Literals  Represents octal value.  Begins with 0o.  Hexadecimal Literals  Represents hexadecimal value.  Begins with 0x.  Decimal Literals  Represents decimal value.  Begins with nothing. Everything you declare in integer literal is of type decimal. Kanika Sharma 7
  • 8. Types of Literal  String Literal  Character Literal  Decimal  Boolean Kanika Sharma 8
  • 9. Best practices for naming Variable & Constants  Choose a name that makes sense. For example, var name makes more sense than var n.  Use camelCase notation to declare a variable or a constant. Camel-case notation starts with lowercase letter.  You can also define variables and constants without labeling it. Not labeling with name means you are not going to use it in the program.  Use constants if you only need to set a value once and never need to change it again during a program. However, if you do need to change it at a later point, use variables.  Constant and variable names cannot contain whitespace characters, mathematical symbols, arrows, private-use (or invalid) Unicode code points, or line- and box-drawing characters. Nor can they begin with a number, although numbers may be included elsewhere within the name. Kanika Sharma 9
  • 10. Using print statement  Printing to the screen using simple print() function  Print(“hello”)  Printing constants, variables and literals  Print(45)  Printing without a link break using terminator parameter  print("Hello”, terminator: " ")  print(“MCA")  print(“Welcome") Kanika Sharma 10
  • 11. Using print statement  Printing multiple items using single print function  print(“Welcome to", 2020, “MCA", separator: " ")  Printing multiple lines  print("Hello, rMCA")  Printing multiple lines using triple quotes  print("""  Hello,  MCA  """) Kanika Sharma 11
  • 12. Using print statement  Printing variables using string interpolation var a = 10 var b = 20 var c = a + b print("sum of (a) and (b) is",c) Kanika Sharma 12
  • 13. Example on print var a = 10print(a) // Value print(111) //Literal print("Welcome",terminator:" ") print("MCA") print("Bye") print("welcome","MCA","in",2020, separator:" .") print("Hello rMCA") print(""“ I Am SWIFT """) Kanika Sharma 13
  • 14. Data Types  Swift offers a collection of built-in data types which are string, integer, floating-point numbers, and Booleans. Kanika Sharma 14
  • 15. Integers(Int)  Integers (Int) are whole numbers.  Variable/Constant declared of integer type can store whole numbers both positive and negative including zero with no fractional components .  Default Value: 0  Size: 32/64 bit depends on the platform type.  Range: -2,147,483,648 to 2,147,483,647 (32 bit platform)  -9223372036854775808 to 9223372036854775807 (64 bit platform  There are many variants of Integer type.e.g. UInt, Int8, Int16 etc. The most common one you use is of Int.  If you have a requirement to specify the size/type of integer a variable/constant can hold, you can store it more specifically using UInt, Int8, Int16 etc. Kanika Sharma 15
  • 16. Integers(Int8)  Int8  Variant of Integer type that can store both positive and negative small numbers.  Default Value: 0  Size: 8 bit  Range: -128 to 127  You can also find out the highest and lowest value a type can store using .min and .max . Kanika Sharma 16
  • 17. Integers(Uint)  Variant of Integer type called UInt (Unsigned Integer) which can only store unsigned numbers (positive or zero).  Default Value: 0  Size: 32/64 bit depends on the platform type.  Range: 0 to 4294967295 (32 bit platform)  0 to 18446744073709551615 (64 bit platform) Kanika Sharma 17
  • 18. Floating Point (Float)  Variables or Constants declared of float type can store number with decimal or fraction points.  Floating-point numbers are numbers with a fractional component, such as 4.993, 0.5, and −234.99.  Default Value: 0.0  Size: 32 bit floating point number.  Range: 1.2*10-38 to 3.4 * 1038 (~6 digits) Kanika Sharma 18
  • 19. Floating Point (Double)  Variables / Constants declared of Double type also stores number with decimal or fraction points as Float but larger decimal points than Float supports.  Default value : 0.0  Size: 64-bit floating point number. (Therefore, a variable of type Double can store number with decimal or fraction points larger than Float supports)  Range: 2.3*10-308 to 1.7*10308 (~15 digits) Kanika Sharma 19
  • 20. Boolean(Bool)  Booleans (bools) are referred to as logical because they can either be true or false.  Variable/Constant declared of Bool type can store only two values either true or false.  Use Booleans when you need to determine whether some logic is true or false.  Default Value: false Kanika Sharma 20
  • 21. Character  Variables/Constants declared of Character type can store a single- character string literal.  You can include emoji or languages other than english as an character in Swift using escape sequence u{n} (unicode code point ,n is in hexadecimal) Kanika Sharma 21
  • 22. String  Variables or Constants declared of String type can store collection of characters.  Default Value: "" (Empty String)  It is Value type.  You can use for-in loop to iterate over a string.  Swift also supports a few special escape sequences to use them in string. For example,  0 (null character),  (a plain backslash ),  t (a tab character),  v (a vertical tab),  r (carriage return),  " (double quote),  ' (single quote), and  u{n} (unicode code point ,n is in hexadecimal). Kanika Sharma 22
  • 23. Comments  Comments are a great way to create notes or reminders to yourself. When you comment code, it means that it will not execute when your code runs. There are two types of comments used: // or /* */. // is used for a one-line comment and /**/ is used for a block of text. Kanika Sharma 23