SlideShare a Scribd company logo
1 of 31
Download to read offline
Introduction to Swift
Lecture 02
Jonathan R. Engelsma, Ph.D.
TOPICS
• Swift Language Overview
• Our first program!
• Variables and constants
• Strings
• CollectionTypes
• Control Flow
• Functions
THE SWIFT PROGRAMMING
LANGUAGE
• A surprise introduced by Apple @ WWDC in June 2014.
• An industrial-quality systems programming language that is as
expressive and enjoyable to use as a scripting language.
• Seamless access to existing Cocoa frameworks.
• Successor to legacy Objective-C language, but provides mix-
and-match interoperability with Objective-C code.
WHY A NEW LANGUAGE?
• Easier for new programmers to get up to speed in iOS
development.
• New language was necessary in order to ensure compatibility
with existing frameworks.
• Easier to create a new language that feels modern, but still
adapts to Objective-C / C conventions.
SWIFT CHARACTERISTICS
• Compiled: source —> bytecodes, not interpreted.
• Strong and static typing: types are clearly identified and
cannot change (e.g. compiler generates faster safer code).
• Automatic ref counting: objects are automatically freed from
memory when there are no more references.
• Name-spaced: makes our code easier to coexist with other
people’s code.
OUR OBLIGATORY FIRST
PROGRAM!
• a complete Swift program!
• no imports / includes!
• no main program - code
written at global scope
becomes the entry point.
• No semicolons!
CONSTANTS
• Use the “let” statement to define constants.
• values doesn’t need to be known at compile time, but can be
assigned only once.
• value assigned must be the same type as the variable name.
• Types can be implicit or explicit.
VARIABLES
• Use the “var” statement to define variables - values can be
mutated!
• value assigned must be the same type as the variable name.
• Types can be implicit or explicit.
• Type conversion is explicit.
STRINGS
• String type is an ordered collection of Character:“hello, world”
• Bridged to NSString in Objective-C.
• String is a value type: copied when passed to function or
method. (different than NSString in this regard!)
• Strings defined with var can be mutated, strings defined with let
cannot be mutated!
STRINGS
• concatenation: can be accomplished with the + operator
• interpolation: can construct new strings from a mix of values/
expressions. using ().
• Compare using == operator.
• Use the hasPrefix / hasSuffix methods to check how a string
starts/ends.
STRINGS
ARRAYS IN SWIFT
• Arrays store ordered lists of values
• All values in a given array are of the same type
• Values are accessed via methods, properties and subscripting.
ARRAYS
DICTIONARIES IN SWIFT
• Dictionaries store multiple values of the same type
• Each value is associated with a unique key
• Do not have to be in a specified order
• Use just like a real world dictionary: e.g. when you want to
look up the definition of a particular key value
• Keys must be hashable
DICTIONARIES
CONTROL FLOW
• for-in statements:
CONTROL FLOW
• while & do-while statements:
CONTROL FLOW
• if / if-else
SWITCH STATEMENT
• Similar to C syntax, but with some notable differences:
• No need to use break statements!
• No implicit fall through
• Each case must contain at least one executable statement
• Case condition can be scalar, range, or tuple!
• Case condition can actually bind values.
CONTROL FLOW
• switch statement
FUNCTIONS
• Self-contained chunks of code that perform a specific task.
• Functions are typed by the return type and type of the
parameters.
• Swift supports first-class functions, e.g. functions can be passed
as arguments and serve as return values.
• Functions in Swift can be nested.
• Swift functions can have multiple return values.
FUNCTIONS
FUNCTIONS
FUNCTIONS
Returning multiple values from a function:
FUNCTIONS
• So far, all the functions we’ve seen defined what are known as
local parameter names. E.g. they are only referred to in the
function implementation.
• Sometimes its useful to name parameters when you call a
function. These are called external parameter names.
FUNCTIONS
• external parameter names:
FUNCTIONS
• shorthand for external parameter names:
FUNCTIONTYPES
• Variable that refer to functions can be defined:
FUNCTIONTYPES
• Functions can be passed as parameters:
FUNCTIONTYPES
• Functions can be returned from functions:
NESTED FUNCTIONS
• We can rewrite the previous examples with nested funcs:

More Related Content

What's hot

Diving Into Scala Cats - Semigroups and Monoids
Diving Into Scala Cats - Semigroups and MonoidsDiving Into Scala Cats - Semigroups and Monoids
Diving Into Scala Cats - Semigroups and MonoidsKnoldus Inc.
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And ComponentsDaniel Fagnan
 
Introduction of lambda expression and predicate builder
Introduction of lambda expression and predicate builderIntroduction of lambda expression and predicate builder
Introduction of lambda expression and predicate builderLearningTech
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Kiran Jonnalagadda
 
iOS development using Swift - Swift Basics (1)
iOS development using Swift - Swift Basics (1)iOS development using Swift - Swift Basics (1)
iOS development using Swift - Swift Basics (1)Ahmed Ali
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)Ahmed Ali
 
Clojure's take on concurrency
Clojure's take on concurrencyClojure's take on concurrency
Clojure's take on concurrencyyoavrubin
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuSrimanta Sahu
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
 

What's hot (20)

java token
java tokenjava token
java token
 
Scala’s implicits
Scala’s implicitsScala’s implicits
Scala’s implicits
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
Diving Into Scala Cats - Semigroups and Monoids
Diving Into Scala Cats - Semigroups and MonoidsDiving Into Scala Cats - Semigroups and Monoids
Diving Into Scala Cats - Semigroups and Monoids
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
 
Introduction of lambda expression and predicate builder
Introduction of lambda expression and predicate builderIntroduction of lambda expression and predicate builder
Introduction of lambda expression and predicate builder
 
Java tokens
Java tokensJava tokens
Java tokens
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)
 
Swift
SwiftSwift
Swift
 
iOS development using Swift - Swift Basics (1)
iOS development using Swift - Swift Basics (1)iOS development using Swift - Swift Basics (1)
iOS development using Swift - Swift Basics (1)
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)
 
Clojure's take on concurrency
Clojure's take on concurrencyClojure's take on concurrency
Clojure's take on concurrency
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 

Viewers also liked

Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageGiuseppe Arici
 
Swift language - A fast overview of some features
Swift language - A fast overview of some featuresSwift language - A fast overview of some features
Swift language - A fast overview of some featuresWeverton Timoteo
 
IOS Swift language 2nd tutorial
IOS Swift language 2nd tutorialIOS Swift language 2nd tutorial
IOS Swift language 2nd tutorialHassan A-j
 
What Every IT Manager Should Know About Mobile Apps
What Every IT Manager Should Know About Mobile AppsWhat Every IT Manager Should Know About Mobile Apps
What Every IT Manager Should Know About Mobile AppsJonathan Engelsma
 
2013 Michigan Beekeepers Association Annual Spring Conference
2013 Michigan Beekeepers Association Annual Spring Conference2013 Michigan Beekeepers Association Annual Spring Conference
2013 Michigan Beekeepers Association Annual Spring ConferenceJonathan Engelsma
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)Jonathan Engelsma
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)Jonathan Engelsma
 
Knowing Your Bees: Becoming a Better Beekeeper
Knowing Your Bees: Becoming a Better BeekeeperKnowing Your Bees: Becoming a Better Beekeeper
Knowing Your Bees: Becoming a Better BeekeeperJonathan Engelsma
 
2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...
2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...
2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...Jonathan Engelsma
 
Beginning iOS Development with Swift
Beginning iOS Development with SwiftBeginning iOS Development with Swift
Beginning iOS Development with SwiftTurnToTech
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)Jonathan Engelsma
 
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 LanguageHossam Ghareeb
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftWorkhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftVisual Engineering
 
Никита Корчагин - iOS development information
Никита Корчагин - iOS development informationНикита Корчагин - iOS development information
Никита Корчагин - iOS development informationDataArt
 

Viewers also liked (15)

Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Swift language - A fast overview of some features
Swift language - A fast overview of some featuresSwift language - A fast overview of some features
Swift language - A fast overview of some features
 
IOS Swift language 2nd tutorial
IOS Swift language 2nd tutorialIOS Swift language 2nd tutorial
IOS Swift language 2nd tutorial
 
What Every IT Manager Should Know About Mobile Apps
What Every IT Manager Should Know About Mobile AppsWhat Every IT Manager Should Know About Mobile Apps
What Every IT Manager Should Know About Mobile Apps
 
2013 Michigan Beekeepers Association Annual Spring Conference
2013 Michigan Beekeepers Association Annual Spring Conference2013 Michigan Beekeepers Association Annual Spring Conference
2013 Michigan Beekeepers Association Annual Spring Conference
 
Mobile Gamification
Mobile GamificationMobile Gamification
Mobile Gamification
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 05)
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
 
Knowing Your Bees: Becoming a Better Beekeeper
Knowing Your Bees: Becoming a Better BeekeeperKnowing Your Bees: Becoming a Better Beekeeper
Knowing Your Bees: Becoming a Better Beekeeper
 
2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...
2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...
2012 Michigan Beekeepers Association Annual Spring Conference - Beekeepers On...
 
Beginning iOS Development with Swift
Beginning iOS Development with SwiftBeginning iOS Development with Swift
Beginning iOS Development with Swift
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
 
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
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftWorkhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
 
Никита Корчагин - iOS development information
Никита Корчагин - iOS development informationНикита Корчагин - iOS development information
Никита Корчагин - iOS development information
 

Similar to iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)

Swift programming language
Swift programming languageSwift programming language
Swift programming languageNijo Job
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaBrian Topping
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageZubayer Farazi
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Welcome to New Swift: Library Evolution & LSP Support
Welcome to New Swift: Library Evolution & LSP SupportWelcome to New Swift: Library Evolution & LSP Support
Welcome to New Swift: Library Evolution & LSP SupportG ABHISEK
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scriptingAmirul Shafeeq
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Inputprimeteacher32
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 
Python first day
Python first dayPython first day
Python first dayfarkhand
 

Similar to iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) (20)

Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
 
Subprogram
SubprogramSubprogram
Subprogram
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
 
Java introduction
Java introductionJava introduction
Java introduction
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
C# basics...
C# basics...C# basics...
C# basics...
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Welcome to New Swift: Library Evolution & LSP Support
Welcome to New Swift: Library Evolution & LSP SupportWelcome to New Swift: Library Evolution & LSP Support
Welcome to New Swift: Library Evolution & LSP Support
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Java script
Java scriptJava script
Java script
 
Python first day
Python first dayPython first day
Python first day
 
Python first day
Python first dayPython first day
Python first day
 
Java script basics
Java script basicsJava script basics
Java script basics
 

More from Jonathan Engelsma

BIP Hive Scale Program Overview
BIP Hive Scale Program OverviewBIP Hive Scale Program Overview
BIP Hive Scale Program OverviewJonathan Engelsma
 
Selling Honey at Farmers Markets, Expos, etc.
Selling Honey at Farmers Markets, Expos, etc. Selling Honey at Farmers Markets, Expos, etc.
Selling Honey at Farmers Markets, Expos, etc. Jonathan Engelsma
 
Harvesting and Handling Honey for Hobby and Small Sideline Beekeepers
Harvesting and Handling Honey for Hobby and Small Sideline BeekeepersHarvesting and Handling Honey for Hobby and Small Sideline Beekeepers
Harvesting and Handling Honey for Hobby and Small Sideline BeekeepersJonathan Engelsma
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)Jonathan Engelsma
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)Jonathan Engelsma
 
So You Want To Be a Beekeeper?
So You Want To Be a Beekeeper? So You Want To Be a Beekeeper?
So You Want To Be a Beekeeper? Jonathan Engelsma
 

More from Jonathan Engelsma (7)

BIP Hive Scale Program Overview
BIP Hive Scale Program OverviewBIP Hive Scale Program Overview
BIP Hive Scale Program Overview
 
Selling Honey Online
Selling Honey OnlineSelling Honey Online
Selling Honey Online
 
Selling Honey at Farmers Markets, Expos, etc.
Selling Honey at Farmers Markets, Expos, etc. Selling Honey at Farmers Markets, Expos, etc.
Selling Honey at Farmers Markets, Expos, etc.
 
Harvesting and Handling Honey for Hobby and Small Sideline Beekeepers
Harvesting and Handling Honey for Hobby and Small Sideline BeekeepersHarvesting and Handling Honey for Hobby and Small Sideline Beekeepers
Harvesting and Handling Honey for Hobby and Small Sideline Beekeepers
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 09)
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
 
So You Want To Be a Beekeeper?
So You Want To Be a Beekeeper? So You Want To Be a Beekeeper?
So You Want To Be a Beekeeper?
 

Recently uploaded

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 

iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)

  • 1. Introduction to Swift Lecture 02 Jonathan R. Engelsma, Ph.D.
  • 2. TOPICS • Swift Language Overview • Our first program! • Variables and constants • Strings • CollectionTypes • Control Flow • Functions
  • 3. THE SWIFT PROGRAMMING LANGUAGE • A surprise introduced by Apple @ WWDC in June 2014. • An industrial-quality systems programming language that is as expressive and enjoyable to use as a scripting language. • Seamless access to existing Cocoa frameworks. • Successor to legacy Objective-C language, but provides mix- and-match interoperability with Objective-C code.
  • 4. WHY A NEW LANGUAGE? • Easier for new programmers to get up to speed in iOS development. • New language was necessary in order to ensure compatibility with existing frameworks. • Easier to create a new language that feels modern, but still adapts to Objective-C / C conventions.
  • 5. SWIFT CHARACTERISTICS • Compiled: source —> bytecodes, not interpreted. • Strong and static typing: types are clearly identified and cannot change (e.g. compiler generates faster safer code). • Automatic ref counting: objects are automatically freed from memory when there are no more references. • Name-spaced: makes our code easier to coexist with other people’s code.
  • 6. OUR OBLIGATORY FIRST PROGRAM! • a complete Swift program! • no imports / includes! • no main program - code written at global scope becomes the entry point. • No semicolons!
  • 7. CONSTANTS • Use the “let” statement to define constants. • values doesn’t need to be known at compile time, but can be assigned only once. • value assigned must be the same type as the variable name. • Types can be implicit or explicit.
  • 8. VARIABLES • Use the “var” statement to define variables - values can be mutated! • value assigned must be the same type as the variable name. • Types can be implicit or explicit. • Type conversion is explicit.
  • 9. STRINGS • String type is an ordered collection of Character:“hello, world” • Bridged to NSString in Objective-C. • String is a value type: copied when passed to function or method. (different than NSString in this regard!) • Strings defined with var can be mutated, strings defined with let cannot be mutated!
  • 10. STRINGS • concatenation: can be accomplished with the + operator • interpolation: can construct new strings from a mix of values/ expressions. using (). • Compare using == operator. • Use the hasPrefix / hasSuffix methods to check how a string starts/ends.
  • 12. ARRAYS IN SWIFT • Arrays store ordered lists of values • All values in a given array are of the same type • Values are accessed via methods, properties and subscripting.
  • 14. DICTIONARIES IN SWIFT • Dictionaries store multiple values of the same type • Each value is associated with a unique key • Do not have to be in a specified order • Use just like a real world dictionary: e.g. when you want to look up the definition of a particular key value • Keys must be hashable
  • 16. CONTROL FLOW • for-in statements:
  • 17. CONTROL FLOW • while & do-while statements:
  • 18. CONTROL FLOW • if / if-else
  • 19. SWITCH STATEMENT • Similar to C syntax, but with some notable differences: • No need to use break statements! • No implicit fall through • Each case must contain at least one executable statement • Case condition can be scalar, range, or tuple! • Case condition can actually bind values.
  • 21. FUNCTIONS • Self-contained chunks of code that perform a specific task. • Functions are typed by the return type and type of the parameters. • Swift supports first-class functions, e.g. functions can be passed as arguments and serve as return values. • Functions in Swift can be nested. • Swift functions can have multiple return values.
  • 25. FUNCTIONS • So far, all the functions we’ve seen defined what are known as local parameter names. E.g. they are only referred to in the function implementation. • Sometimes its useful to name parameters when you call a function. These are called external parameter names.
  • 27. FUNCTIONS • shorthand for external parameter names:
  • 28. FUNCTIONTYPES • Variable that refer to functions can be defined:
  • 29. FUNCTIONTYPES • Functions can be passed as parameters:
  • 30. FUNCTIONTYPES • Functions can be returned from functions:
  • 31. NESTED FUNCTIONS • We can rewrite the previous examples with nested funcs: