SlideShare a Scribd company logo
SWIFT BASICS (2) 
iOS Development using Swift 
Ahmed Ali
TODAY TOPICS 
• Data types 
• Strings 
• Mutability, comparison, and interpolation 
• Collection types 
• Arrays, dictionaries and their mutability 
• Control flow 
• Connecting UI Controls to Your Code 
Ahmed Ali
DATA TYPES 
• Integers 
• Int 
• UInt 
• Floating point 
• Float 
• Double 
• Boolean 
• Bool 
Ahmed Ali
DATA TYPES - TUPLES 
• Multi-values in one reference 
• You can pass a tuple as a method parameter, return it from a function (or method), make 
it the type of a reference. 
• Definition Syntax: 
• var tupleVar : (Int, String) 
• Assigning it a value: 
• tupleVar = (5, "String value”) 
Ahmed Ali
DATA TYPES - TUPLES (CONT) 
• Tuples values can be access through their index number or names 
• Accessing the value through its zero-based index 
let intVal : Int = tupleVar.0 // equal to 5 
let strVal : String = tupleVar.1 // equal to "String Value” 
• Named tuple elements 
let response : (errorCode: Int, errorMessage: String) = 
(404, "HTTP not found") 
print("Error connecting: (response.errorMessage) with error code: 
(response.errorCode)") 
Ahmed Ali
STRINGS 
• Syntax: 
• let myStr = "String value” 
• Mutability (modifiable) 
• If the reference is defined with var keyword then it is mutable (can be modified) 
• If the reference is defined with let keyword then it is immutable (can not be modified) 
• Examples: 
//Valid 
var myStr = "String value" 
myStr += " Additional string" 
Ahmed Ali
STRINGS (CONT) 
• Mutability invalid example: 
//Invalid 
let myStr = "String value" 
myStr += " Additional string" 
Ahmed Ali
STRINGS (CONT) 
• Comparison: 
• You don’t need to call a special method to compare to string references. 
• You can use the == operator is used to compare two string reference and see if they 
hold the same string value. 
• The === can also check against the reference it self, this operator checks if both 
reference are the same, i.e refers to the same memory address. 
Ahmed Ali
STRINGS (CONT) 
• Interpolation 
• Simple syntax: 
let hello = "Hello” 
let world = "World” 
let symbol = "!“ 
let helloWorld = "(hello) (world) (symbol)" 
Ahmed Ali
COLLECTION TYPES - ARRAYS 
• Can hold list of values of the same type. 
• Definition syntax: 
let arr : Array<String> = ["val 1", "val 2", "etc..."] 
//shorthand version 
let arr : [String] = ["val 1", "val 2", "etc..."] 
//Shorter version using type inference 
let arr = ["val 1", "val 2", "etc..."] 
Ahmed Ali
COLLECTION TYPES - ARRAYS (CONT) 
• Access and modify array content: 
//to be modified, it must be a variable 
var arr = ["v1", "v2", "v3"] 
println(arr[0]) //prints first element 
arr[0] = "newV1" //changes first element 
println(arr[0]) 
arr.removeAtIndex(1) //removes second element 
arr.append("anotherNewValue")//appends an element 
arr += ["v4", "v5"] //append more than one element 
Ahmed Ali
COLLECTION TYPES - DICTIONARIES 
• Can hold list of key : value pairs. 
• Definition syntax: 
let dict : Dictionary<String, Int> = ["A" : 15, 
"B" : 16] 
//shorthand version 
let dict : [String: Int] = ["A" : 15, "B" : 16] 
//Shorter version using type inference 
let dict = ["A" : 15, "B" : 16] 
Ahmed Ali
COLLECTION TYPES - DICTIONARIES (CONT) 
• Access and modify dictionary content: 
//to be modified, it must be a variable 
var dict : Dictionary<String, Int> = ["A" : 15, 
"B" : 16] 
println(dict["B"]) //prints 16 
dict["B"] = 30 //modifies the value of "B" key 
dict["C"] = 19 //adds new key : value pairs to the dictionary 
dict.removeValueForKey("A") //removes the key with its value 
Ahmed Ali
CONTROL FLOW - IF 
• Like any traditional if condition you are familiar with, with additional capabilities. 
• Optional binding: 
var dict = ["K" : 15, "G" : 16, ”A" : 5] 
if let value = dict["A"]{ 
println(value) 
} 
Ahmed Ali
CONTROL FLOW - IF (CONT) 
• If condition binding variable to a tuple 
• We can use optional binding to map tuple values to variables 
let params = ["name" : "Ahmed", "pass" : "123456"] 
if let (cached, response) = performHttpRequest("login", params){ 
} 
//or if only one value matters 
if let (_, response) = performHttpRequest("login", params){ 
} 
Ahmed Ali
CONTROL FLOW – FOR 
• Traditional for loop and varieties of for each 
• Traditional for loop: 
let arr = [1, 2, 3, 4, 5, 6, 7] 
//The parentheses here are mandatory in this old style for loop 
for (var i = 0; i < arr.count; i++){ 
} 
Ahmed Ali
CONTROL FLOW – FOR EACH 
• For each 
• Removing the parentheses is mandatory for all varieties of for each loop 
• For each with open range operator: 
for i in 0 ... 10 { 
//this loop will loop from the value 0 to the value 10 (11 loops) 
} 
Ahmed Ali
CONTROL FLOW – FOR EACH (CONT) 
• For each with half open operator: 
for i in 0 ..< 10 { 
//this loop will loop from the value 0 to the value 9 (10 loops) 
} 
Ahmed Ali
CONTROL FLOW – FOR EACH (CONT) 
• For each with arrays: 
let arr = [1, 2, 3, 4, 5, 6, 7] 
for element in arr{ 
} 
Ahmed Ali
CONTROL FLOW – WHILE AND DO .. WHILE 
• While and do .. While, has nothing different than what you already from Java, C, C++ or 
PHP. 
Ahmed Ali
• No implicit fallthrough. 
• No need for break statements. 
• Use fallthrough if you want the 
case to fallthrough. 
• Switch cases can be against non-numeric 
types. 
• Switch cases are exhaustive: all 
possible values must have a matching 
case. 
• Have many varieties to handle range 
matches, tuple mapping, where 
conditions, and bindings. 
let myConst = 2; 
switch myConst{ 
case 1: 
println("myConst = 1") 
case 2: 
println("myConst = 2") 
case 3: 
println("myConst = 3") 
default: 
println("myConst = (myConst)") 
} 
CONTROL FLOW - SWITCH 
Ahmed Ali
CONTROL FLOW – SWITCH (CONT) 
• Range matching example 
• Note: all possible numeric values must 
have a matching case, so a default 
case is mandatory. 
switch myConst{ 
case 0 ... 4: 
println("myConst is between 0 and 
4") 
case 5 ... 50: 
println("myConst is between 5 and 
50") 
case 51 ..< 60: 
println("myConst is between 51 and 
59") 
default: 
println("myConst = (myConst)") 
} 
Ahmed Ali
CONTROL FLOW – SWITCH (CONT) 
• Fallthrough example 
• If the second case is matched, it’ll 
cause all the cases beneath it to be 
executed as well. 
• switch myConst{ 
• case 0 ... 4: 
• println("myConst is between 0 and 4") 
• case 5 ... 50: 
• println("myConst is between 5 and 50") 
• //if this case matched, it'll pass execution to 
the all the cases beneath it 
• fallthrough 
• case 51 ..< 60: 
• println("myConst is between 51 and 59") 
• default: 
• println("myConst = (myConst)") 
• } 
Ahmed Ali
CONTROL FLOW – SWITCH (CONT) 
• let x where ? 
• Binding and where conditions 
switch myConst{ 
case let x where x >= 0 && x < 5: 
println(x); 
case 6..<9: 
println("between 6 and 8") 
case 9, 10, 11, 12: 
println("myConst = (myConst)") 
default: 
println("myConst = (myConst)") 
} 
Ahmed Ali
Connecting UI Controls to Your 
Code

More Related Content

Viewers also liked

Hydal power plant
Hydal power plantHydal power plant
Hydal power plant
Sumalatha kalakotla
 
Comenius tecnologia
Comenius tecnologiaComenius tecnologia
Comenius tecnologia
EcoTour20
 
Hydro ppt
Hydro pptHydro ppt
Hydro ppt
Mayank Rathi
 
wireless Mobile Charging-Tanuj Kumar Pandey(college project)
wireless Mobile Charging-Tanuj Kumar Pandey(college project)wireless Mobile Charging-Tanuj Kumar Pandey(college project)
wireless Mobile Charging-Tanuj Kumar Pandey(college project)
Tanuj Kumar Pandey
 
SARVESH hydro electric-power-plant
SARVESH hydro electric-power-plantSARVESH hydro electric-power-plant
SARVESH hydro electric-power-plant
sarvesh kumar
 
Hydro power plant
Hydro power plantHydro power plant
Hydro power plant
Amitabh Shukla
 
Bera Syul Hydro power project Presentation
Bera Syul Hydro power project PresentationBera Syul Hydro power project Presentation
Bera Syul Hydro power project Presentation
Tanuj Kumar Pandey
 
Project report on THDC Hydrop Power Plant Summer Training
Project report on THDC Hydrop Power Plant Summer TrainingProject report on THDC Hydrop Power Plant Summer Training
Project report on THDC Hydrop Power Plant Summer Training
Charu Kandpal
 
Hydroelectrical power generation
Hydroelectrical power generationHydroelectrical power generation
Hydroelectrical power generation
Yasir Imran
 
Hydro power plant
Hydro power plantHydro power plant
Hydro power plant
Ashvani Shukla
 
HYDROELECTRIC POWER
HYDROELECTRIC POWERHYDROELECTRIC POWER
HYDROELECTRIC POWER
Pankaj Thakur
 
Hydro-Electric Power Plant
Hydro-Electric Power PlantHydro-Electric Power Plant
Hydro-Electric Power Plant
AFAQAHMED JAMADAR
 
فروشنده حرفه ای
فروشنده حرفه ایفروشنده حرفه ای
فروشنده حرفه ای
Mehdi Alinejad
 
Micro Hydro Power Plant
Micro Hydro Power PlantMicro Hydro Power Plant
Micro Hydro Power Plant
Abhishek Verma
 
Micro Hydro Power Background
Micro Hydro Power BackgroundMicro Hydro Power Background
Micro Hydro Power Background
Lonny Grafman
 
koteshwar hydro electric power plant 400 mw
koteshwar hydro electric power plant 400 mwkoteshwar hydro electric power plant 400 mw
koteshwar hydro electric power plant 400 mw
SAIF ALI ZAIDI
 
Presentation=sardar sarovar hydro power plant
Presentation=sardar sarovar hydro power plantPresentation=sardar sarovar hydro power plant
Presentation=sardar sarovar hydro power plant
vishal Barvaliya
 
Micro hydro power plant
Micro hydro power plantMicro hydro power plant
Micro hydro power plant
Saravanan Sivamani
 
Sardar Sarovar Dam
Sardar Sarovar DamSardar Sarovar Dam
Sardar Sarovar Dam
Kp Ahm
 
Small hydro power in india
Small hydro power in indiaSmall hydro power in india
Small hydro power in india
Ashish Verma
 

Viewers also liked (20)

Hydal power plant
Hydal power plantHydal power plant
Hydal power plant
 
Comenius tecnologia
Comenius tecnologiaComenius tecnologia
Comenius tecnologia
 
Hydro ppt
Hydro pptHydro ppt
Hydro ppt
 
wireless Mobile Charging-Tanuj Kumar Pandey(college project)
wireless Mobile Charging-Tanuj Kumar Pandey(college project)wireless Mobile Charging-Tanuj Kumar Pandey(college project)
wireless Mobile Charging-Tanuj Kumar Pandey(college project)
 
SARVESH hydro electric-power-plant
SARVESH hydro electric-power-plantSARVESH hydro electric-power-plant
SARVESH hydro electric-power-plant
 
Hydro power plant
Hydro power plantHydro power plant
Hydro power plant
 
Bera Syul Hydro power project Presentation
Bera Syul Hydro power project PresentationBera Syul Hydro power project Presentation
Bera Syul Hydro power project Presentation
 
Project report on THDC Hydrop Power Plant Summer Training
Project report on THDC Hydrop Power Plant Summer TrainingProject report on THDC Hydrop Power Plant Summer Training
Project report on THDC Hydrop Power Plant Summer Training
 
Hydroelectrical power generation
Hydroelectrical power generationHydroelectrical power generation
Hydroelectrical power generation
 
Hydro power plant
Hydro power plantHydro power plant
Hydro power plant
 
HYDROELECTRIC POWER
HYDROELECTRIC POWERHYDROELECTRIC POWER
HYDROELECTRIC POWER
 
Hydro-Electric Power Plant
Hydro-Electric Power PlantHydro-Electric Power Plant
Hydro-Electric Power Plant
 
فروشنده حرفه ای
فروشنده حرفه ایفروشنده حرفه ای
فروشنده حرفه ای
 
Micro Hydro Power Plant
Micro Hydro Power PlantMicro Hydro Power Plant
Micro Hydro Power Plant
 
Micro Hydro Power Background
Micro Hydro Power BackgroundMicro Hydro Power Background
Micro Hydro Power Background
 
koteshwar hydro electric power plant 400 mw
koteshwar hydro electric power plant 400 mwkoteshwar hydro electric power plant 400 mw
koteshwar hydro electric power plant 400 mw
 
Presentation=sardar sarovar hydro power plant
Presentation=sardar sarovar hydro power plantPresentation=sardar sarovar hydro power plant
Presentation=sardar sarovar hydro power plant
 
Micro hydro power plant
Micro hydro power plantMicro hydro power plant
Micro hydro power plant
 
Sardar Sarovar Dam
Sardar Sarovar DamSardar Sarovar Dam
Sardar Sarovar Dam
 
Small hydro power in india
Small hydro power in indiaSmall hydro power in india
Small hydro power in india
 

Similar to iOS development using Swift - Swift Basics (2)

iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...
iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...
iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...
Ahmed Ali
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
Kazunobu Tasaka
 
Swift as an OOP Language
Swift as an OOP LanguageSwift as an OOP Language
Swift as an OOP Language
Ahmed Ali
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
For Beginners - C#
For Beginners - C#For Beginners - C#
For Beginners - C#
Snehal Harawande
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
Rohit Rao
 
Swift Basics
Swift BasicsSwift Basics
Swift Basics
Hirakawa Akira
 
Lecture 2
Lecture 2Lecture 2
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
Ben Miu CIM® FCSI A+
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
jewelyngrace
 
Hive - ORIEN IT
Hive - ORIEN ITHive - ORIEN IT
Hive - ORIEN IT
ORIEN IT
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
Hemantha Kulathilake
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
ZubairAli256321
 
Aspdot
AspdotAspdot
Introduction to Swift (tutorial)
Introduction to Swift (tutorial)Introduction to Swift (tutorial)
Introduction to Swift (tutorial)
Bruno Delb
 
A Quick Taste of C
A Quick Taste of CA Quick Taste of C
A Quick Taste of C
jeremyrand
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
jessitron
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
SURBHI SAROHA
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
Ankit Dubey
 

Similar to iOS development using Swift - Swift Basics (2) (20)

iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...
iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...
iOS Development using Swift: Enums, ARC, Delegation, Closures, Table View and...
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
Swift as an OOP Language
Swift as an OOP LanguageSwift as an OOP Language
Swift as an OOP Language
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
For Beginners - C#
For Beginners - C#For Beginners - C#
For Beginners - C#
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 
Swift Basics
Swift BasicsSwift Basics
Swift Basics
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Hive - ORIEN IT
Hive - ORIEN ITHive - ORIEN IT
Hive - ORIEN IT
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
 
Aspdot
AspdotAspdot
Aspdot
 
Introduction to Swift (tutorial)
Introduction to Swift (tutorial)Introduction to Swift (tutorial)
Introduction to Swift (tutorial)
 
A Quick Taste of C
A Quick Taste of CA Quick Taste of C
A Quick Taste of C
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 

Recently uploaded

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 

Recently uploaded (20)

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 

iOS development using Swift - Swift Basics (2)

  • 1. SWIFT BASICS (2) iOS Development using Swift Ahmed Ali
  • 2. TODAY TOPICS • Data types • Strings • Mutability, comparison, and interpolation • Collection types • Arrays, dictionaries and their mutability • Control flow • Connecting UI Controls to Your Code Ahmed Ali
  • 3. DATA TYPES • Integers • Int • UInt • Floating point • Float • Double • Boolean • Bool Ahmed Ali
  • 4. DATA TYPES - TUPLES • Multi-values in one reference • You can pass a tuple as a method parameter, return it from a function (or method), make it the type of a reference. • Definition Syntax: • var tupleVar : (Int, String) • Assigning it a value: • tupleVar = (5, "String value”) Ahmed Ali
  • 5. DATA TYPES - TUPLES (CONT) • Tuples values can be access through their index number or names • Accessing the value through its zero-based index let intVal : Int = tupleVar.0 // equal to 5 let strVal : String = tupleVar.1 // equal to "String Value” • Named tuple elements let response : (errorCode: Int, errorMessage: String) = (404, "HTTP not found") print("Error connecting: (response.errorMessage) with error code: (response.errorCode)") Ahmed Ali
  • 6. STRINGS • Syntax: • let myStr = "String value” • Mutability (modifiable) • If the reference is defined with var keyword then it is mutable (can be modified) • If the reference is defined with let keyword then it is immutable (can not be modified) • Examples: //Valid var myStr = "String value" myStr += " Additional string" Ahmed Ali
  • 7. STRINGS (CONT) • Mutability invalid example: //Invalid let myStr = "String value" myStr += " Additional string" Ahmed Ali
  • 8. STRINGS (CONT) • Comparison: • You don’t need to call a special method to compare to string references. • You can use the == operator is used to compare two string reference and see if they hold the same string value. • The === can also check against the reference it self, this operator checks if both reference are the same, i.e refers to the same memory address. Ahmed Ali
  • 9. STRINGS (CONT) • Interpolation • Simple syntax: let hello = "Hello” let world = "World” let symbol = "!“ let helloWorld = "(hello) (world) (symbol)" Ahmed Ali
  • 10. COLLECTION TYPES - ARRAYS • Can hold list of values of the same type. • Definition syntax: let arr : Array<String> = ["val 1", "val 2", "etc..."] //shorthand version let arr : [String] = ["val 1", "val 2", "etc..."] //Shorter version using type inference let arr = ["val 1", "val 2", "etc..."] Ahmed Ali
  • 11. COLLECTION TYPES - ARRAYS (CONT) • Access and modify array content: //to be modified, it must be a variable var arr = ["v1", "v2", "v3"] println(arr[0]) //prints first element arr[0] = "newV1" //changes first element println(arr[0]) arr.removeAtIndex(1) //removes second element arr.append("anotherNewValue")//appends an element arr += ["v4", "v5"] //append more than one element Ahmed Ali
  • 12. COLLECTION TYPES - DICTIONARIES • Can hold list of key : value pairs. • Definition syntax: let dict : Dictionary<String, Int> = ["A" : 15, "B" : 16] //shorthand version let dict : [String: Int] = ["A" : 15, "B" : 16] //Shorter version using type inference let dict = ["A" : 15, "B" : 16] Ahmed Ali
  • 13. COLLECTION TYPES - DICTIONARIES (CONT) • Access and modify dictionary content: //to be modified, it must be a variable var dict : Dictionary<String, Int> = ["A" : 15, "B" : 16] println(dict["B"]) //prints 16 dict["B"] = 30 //modifies the value of "B" key dict["C"] = 19 //adds new key : value pairs to the dictionary dict.removeValueForKey("A") //removes the key with its value Ahmed Ali
  • 14. CONTROL FLOW - IF • Like any traditional if condition you are familiar with, with additional capabilities. • Optional binding: var dict = ["K" : 15, "G" : 16, ”A" : 5] if let value = dict["A"]{ println(value) } Ahmed Ali
  • 15. CONTROL FLOW - IF (CONT) • If condition binding variable to a tuple • We can use optional binding to map tuple values to variables let params = ["name" : "Ahmed", "pass" : "123456"] if let (cached, response) = performHttpRequest("login", params){ } //or if only one value matters if let (_, response) = performHttpRequest("login", params){ } Ahmed Ali
  • 16. CONTROL FLOW – FOR • Traditional for loop and varieties of for each • Traditional for loop: let arr = [1, 2, 3, 4, 5, 6, 7] //The parentheses here are mandatory in this old style for loop for (var i = 0; i < arr.count; i++){ } Ahmed Ali
  • 17. CONTROL FLOW – FOR EACH • For each • Removing the parentheses is mandatory for all varieties of for each loop • For each with open range operator: for i in 0 ... 10 { //this loop will loop from the value 0 to the value 10 (11 loops) } Ahmed Ali
  • 18. CONTROL FLOW – FOR EACH (CONT) • For each with half open operator: for i in 0 ..< 10 { //this loop will loop from the value 0 to the value 9 (10 loops) } Ahmed Ali
  • 19. CONTROL FLOW – FOR EACH (CONT) • For each with arrays: let arr = [1, 2, 3, 4, 5, 6, 7] for element in arr{ } Ahmed Ali
  • 20. CONTROL FLOW – WHILE AND DO .. WHILE • While and do .. While, has nothing different than what you already from Java, C, C++ or PHP. Ahmed Ali
  • 21. • No implicit fallthrough. • No need for break statements. • Use fallthrough if you want the case to fallthrough. • Switch cases can be against non-numeric types. • Switch cases are exhaustive: all possible values must have a matching case. • Have many varieties to handle range matches, tuple mapping, where conditions, and bindings. let myConst = 2; switch myConst{ case 1: println("myConst = 1") case 2: println("myConst = 2") case 3: println("myConst = 3") default: println("myConst = (myConst)") } CONTROL FLOW - SWITCH Ahmed Ali
  • 22. CONTROL FLOW – SWITCH (CONT) • Range matching example • Note: all possible numeric values must have a matching case, so a default case is mandatory. switch myConst{ case 0 ... 4: println("myConst is between 0 and 4") case 5 ... 50: println("myConst is between 5 and 50") case 51 ..< 60: println("myConst is between 51 and 59") default: println("myConst = (myConst)") } Ahmed Ali
  • 23. CONTROL FLOW – SWITCH (CONT) • Fallthrough example • If the second case is matched, it’ll cause all the cases beneath it to be executed as well. • switch myConst{ • case 0 ... 4: • println("myConst is between 0 and 4") • case 5 ... 50: • println("myConst is between 5 and 50") • //if this case matched, it'll pass execution to the all the cases beneath it • fallthrough • case 51 ..< 60: • println("myConst is between 51 and 59") • default: • println("myConst = (myConst)") • } Ahmed Ali
  • 24. CONTROL FLOW – SWITCH (CONT) • let x where ? • Binding and where conditions switch myConst{ case let x where x >= 0 && x < 5: println(x); case 6..<9: println("between 6 and 8") case 9, 10, 11, 12: println("myConst = (myConst)") default: println("myConst = (myConst)") } Ahmed Ali
  • 25. Connecting UI Controls to Your Code