SlideShare a Scribd company logo
1 of 10
SWIFT BASICS (1) 
iOS Development using Swift 
Ahmed Ali
TODAY TOPICS 
• What is and Why Swift? 
• Swift: basic information. 
• Variables 
• Constants 
• Swift type inference 
• Quick demo 
Ahmed Ali
WHAT IS AND WHY SWIFT 
• Swift is the brand new language for developing iOS and Mac OS X applications. 
• Supports many modern features. 
• Strictly-typed language. 
• Better compile time validation. 
Ahmed Ali
BASICS 
• No main method. 
• The trailing semicolon after every statement is optional. 
• The parentheses in if condition, for, while loops are optional. 
• OOP and Procedural programming are fully supported. 
Ahmed Ali
VARIABLES 
• Defining variable syntax: 
var myVar : Int = 0 
• Allow nil, optional variables syntax: 
var myVar : Int? 
• You have to unwrap optional variables to access their values: 
var nonOptionalVar : Int = myVar! 
• Unwrapping variable who has no value (or its value is nil) will trigger a crash. 
• Check if an optional has a value before trying to unwrap it: 
if myVar != nil { 
print("myVar equale to(myVar!)") 
} 
Ahmed Ali
VARIABLES (CONT) 
• Optional Binding: 
if let myConst : Int = myVar{ 
print("myVar has the value (myConst)") 
} 
• Implicitly unwrapped optional: 
var myVar : Int! 
Ahmed Ali
VARIABLES (CONT) 
• Normal optional vs implicitly unwrapped optional: 
• Behind the scene they are the same thing. 
• Implicitly unwrapped is used whenever you are sure once it has a value, it’ll always 
has a value. 
• You can check implicitly unwrapped optional, or bind them in if conditions as you do 
with normal optional. 
Ahmed Ali
CONSTANTS 
• Constants are preferred when a value will not change. 
• Can be defined as optional, however, their value will not change. 
• Definition syntax: 
let constant : String = "Constant value" 
Ahmed Ali
TYPE INFERENCE 
• You don’t always have to write the type explicitly. 
• Swift compiler is smart enough to try to get the right type from the current context. 
let constant = "Constant value" 
Ahmed Ali
Demo Time 
Ahmed Ali

More Related Content

Viewers also liked

Swift: The Basics
Swift: The BasicsSwift: The Basics
Swift: The BasicsMarc Brown
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift TalkGabriel Lim
 
Rawnet Lightning Talk - Swift iOS Development
Rawnet Lightning Talk -  Swift iOS DevelopmentRawnet Lightning Talk -  Swift iOS Development
Rawnet Lightning Talk - Swift iOS DevelopmentRawnet
 
A Swift Introduction to iOS 10
A Swift Introduction to iOS 10A Swift Introduction to iOS 10
A Swift Introduction to iOS 10James Sugrue
 
To swiftly go where no OS has gone before
To swiftly go where no OS has gone beforeTo swiftly go where no OS has gone before
To swiftly go where no OS has gone beforePaul Ardeleanu
 
Class vs struct for Swift
Class vs struct for SwiftClass vs struct for Swift
Class vs struct for SwiftHirakawa Akira
 
Introduction to iOS Apps Development
Introduction to iOS Apps DevelopmentIntroduction to iOS Apps Development
Introduction to iOS Apps DevelopmentProf. Erwin Globio
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 

Viewers also liked (11)

Swift: The Basics
Swift: The BasicsSwift: The Basics
Swift: The Basics
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
 
Rawnet Lightning Talk - Swift iOS Development
Rawnet Lightning Talk -  Swift iOS DevelopmentRawnet Lightning Talk -  Swift iOS Development
Rawnet Lightning Talk - Swift iOS Development
 
Generics With Swift
Generics With SwiftGenerics With Swift
Generics With Swift
 
A Swift Introduction to iOS 10
A Swift Introduction to iOS 10A Swift Introduction to iOS 10
A Swift Introduction to iOS 10
 
SWIFT 3
SWIFT 3SWIFT 3
SWIFT 3
 
To swiftly go where no OS has gone before
To swiftly go where no OS has gone beforeTo swiftly go where no OS has gone before
To swiftly go where no OS has gone before
 
Class vs struct for Swift
Class vs struct for SwiftClass vs struct for Swift
Class vs struct for Swift
 
Introduction to iOS Apps Development
Introduction to iOS Apps DevelopmentIntroduction to iOS Apps Development
Introduction to iOS Apps Development
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 

Recently uploaded

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

iOS development using Swift - Swift Basics (1)

  • 1. SWIFT BASICS (1) iOS Development using Swift Ahmed Ali
  • 2. TODAY TOPICS • What is and Why Swift? • Swift: basic information. • Variables • Constants • Swift type inference • Quick demo Ahmed Ali
  • 3. WHAT IS AND WHY SWIFT • Swift is the brand new language for developing iOS and Mac OS X applications. • Supports many modern features. • Strictly-typed language. • Better compile time validation. Ahmed Ali
  • 4. BASICS • No main method. • The trailing semicolon after every statement is optional. • The parentheses in if condition, for, while loops are optional. • OOP and Procedural programming are fully supported. Ahmed Ali
  • 5. VARIABLES • Defining variable syntax: var myVar : Int = 0 • Allow nil, optional variables syntax: var myVar : Int? • You have to unwrap optional variables to access their values: var nonOptionalVar : Int = myVar! • Unwrapping variable who has no value (or its value is nil) will trigger a crash. • Check if an optional has a value before trying to unwrap it: if myVar != nil { print("myVar equale to(myVar!)") } Ahmed Ali
  • 6. VARIABLES (CONT) • Optional Binding: if let myConst : Int = myVar{ print("myVar has the value (myConst)") } • Implicitly unwrapped optional: var myVar : Int! Ahmed Ali
  • 7. VARIABLES (CONT) • Normal optional vs implicitly unwrapped optional: • Behind the scene they are the same thing. • Implicitly unwrapped is used whenever you are sure once it has a value, it’ll always has a value. • You can check implicitly unwrapped optional, or bind them in if conditions as you do with normal optional. Ahmed Ali
  • 8. CONSTANTS • Constants are preferred when a value will not change. • Can be defined as optional, however, their value will not change. • Definition syntax: let constant : String = "Constant value" Ahmed Ali
  • 9. TYPE INFERENCE • You don’t always have to write the type explicitly. • Swift compiler is smart enough to try to get the right type from the current context. let constant = "Constant value" Ahmed Ali