SlideShare a Scribd company logo
Quick Swift Tour
Swift Language 
• Fast! 
• Modern! 
• Safe! 
• Interactive
Fast 
• Swift code is compiled and optimised by the 
advanced LLVM compiler 
• ARM and x86-64 native code 
• Tuned native collections 
• Swift-specific optimiser 
• C-like procedural performance
Modern 
• Clean syntax! 
• No headers! 
• No semicolons ! 
• Multiple return values! 
• Optional arguments ! 
• Closures! 
• Generics
Safe 
• Type safety with type inference! 
• No uninitialized data! 
• Array bounds checks! 
• Restricts direct access to pointers! 
• Automatically manages memory using ARC
Interactive 
• REPL 
• Playgrounds
Swift Tour
• Variable and Constant! 
• String! 
• Array, Dictionary! 
• Optionals! 
• Control Flow! 
• Function / Closure! 
• Class! 
• Enum / Struct! 
• Protocol / Extension! 
• Generics
Variables / Constants 
! 
// variable 
var myVariable = 42 
myVariable = 50 
! 
// constant 
let myConstant = 42 
//myConstant = 1 <- compile error 
! 
! 
// How to specify type 
var age: Int = 34 
let distance: Double = 2.0
String 
! 
let age = 34 
let label = "Age: " 
! 
! 
// Values are never implicitly converted to 
another type. 
let desc1 = label + String(age) 
! 
// Simpler way with a backslash() 
let desc2 = "Age: (age)”
Array, Dictionary 
! 
// Create arrays and dictionaries using brackets ([]) 
! 
// Array 
var iOSMembers = ["ichinose", "hato", "horimi", 
"tasaka", "watanabe"] 
! 
// Dictionary 
let appMember = ["ios": iOSMembers] 
! 
! 
// Use initializer syntax to create an empty array or 
dictionary 
var emptyArray = [String]() 
var emptyDict = [String: Int]()
Optionals
nil in Swift 
• Swift’s nil is not the same as nil in Objective-C. 
In Swift, nil cannot be set to variables and 
constants… 
! 
var value: Int = 10 
value = nil // compile error 
let value1: String = nil // compile error 
• Objective-C: 
nil is a pointer to a nonexistent object. 
• Swift: 
nil is the absence of a value.
Optionals 
• Optionals indicate that a constant or variable is 
allowed to have “no value” 
! 
var serverResponseCode: Int? = 404 
// serverResponseCode contains an actual Int value of 
404 
! 
serverResponseCode = nil 
// serverResponseCode now contains no value 
! 
// When no default value is set, 
// surveyAnswer is automatically set to nil 
var surveyAnswer: String?
If Statements and 
Forced Unwrapping 
! 
let optionalValue: Int? = 10 
! 
// (==) and (!=) can be used for nil check 
if optionalValue != nil { 
// Use "!" to access underlying value of optionalValue 
println("optionalValue has an integer value of 
(optionalValue!).") 
}
Implicitly Unwrapped Optional 
• Placing an exclamation mark (String!) rather than a question mark (String?) 
• Useful when an optional value will always have a value 
• No need to check and unwrap the optional’s value every time it is accessed 
! 
let possibleString: String? = "An optional string." 
! 
// requires an exclamation mark 
let forcedString: String = possibleString! 
!! 
let assumedString: String! = "An implicitly unwrapped optional 
string." 
! 
// no need for an exclamation mark 
let implicitString: String = assumedString
Control Flow
for 
! 
var firstForLoop = 0 
for i in 0...3 { // equal to 0..<4 
firstForLoop += i 
} 
!! 
let interestingNumbers = [ 
"Prime": [2, 3, 5, 7, 11, 13], 
"Fibonacci": [1, 1, 2, 3, 5, 8], 
] 
var largest = 0 
// key and value can be passed 
for (kind, numbers) in interestingNumbers { 
for number in numbers { 
if number > largest { 
largest = number 
} 
} 
}
switch 
! 
let value: Int = 10 
switch value { 
case 0: 
println("(value)") 
case 1..<3: // range comparison 
println("(value)") 
case 4, 5: 
println("(value)") 
default: 
println("(value)") 
} 
• Flexible matching patterns 
• No break 
• default must appear last
switch 
• switch are NOT limited to integers! 
! 
let vegetable = "red pepper” 
! 
var vegetableComment: String 
switch vegetable { 
case "celery": 
vegetableComment = "Add some raisins and make ants on a log.” 
! 
case "cucumber", "watercress": 
vegetableComment = "That would make a good tea sandwich." 
! 
case let x where x.hasSuffix("pepper"): 
vegetableComment = "Is it a spicy (x)?" 
! 
default: 
vegetableComment = "Everything tastes good in soup." 
}
Functions and Closures
Functions 
func sayHello(personName: String) -> String { 
let greeting = "Hello, " + personName + "!" 
return greeting 
} 
! 
sayHello("Ameba")
Functions 
• Functions are first-class type. 
// return value 
func makeIncrementer() -> (Int -> Int) { 
func addOne(number: Int) -> Int { 
return 1 + number 
} 
return addOne 
} 
! 
// argument 
func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { 
for item in list { 
if condition(item) { return true } 
} 
return false 
} 
func lessThanTen(number: Int) -> Bool { 
return number < 10 
} 
var numbers = [20, 19, 7, 12] 
hasAnyMatches(numbers, lessThanTen)
Closures 
• Similar to blocks in Objective-C! 
• Simple Syntax 
! 
// Closure Expression Syntax 
{ (parameters) -> return type in 
statements 
} 
! 
// e.g. 
let names = ["horimi", "ichinose", "watanabe", "hato", "tasaka"] 
var reversed = sorted(names, { (s1: String, s2: String) -> Bool in 
return s1 > s2 
})
Closures 
! 
// Inferring Type From Context 
reversed = sorted(names, { s1, s2 in return s1 > s2 } ) 
! 
// Implicit Returns from Single-Expression Closures 
reversed = sorted(names, { s1, s2 in s1 > s2 } ) 
! 
// Shorthand Argument Names 
reversed = sorted(names, { $0 > $1 } )
Class
Class 
! 
class NamedShape { 
// properties 
var numberOfSides: Int = 0 
var name: String 
// initializer 
init(name: String) { 
self.name = name 
} 
// method 
func simpleDescription() -> String { 
return "A shape with (numberOfSides) sides." 
} 
}
Inheritance 
! 
class Square: NamedShape { 
var sideLength: Double 
! 
// initializer 
init(sideLength: Double, name: String) { 
// initialize before calling super.init 
self.sideLength = sideLength 
super.init(name: name) 
numberOfSides = 4 
} 
func area() -> Double { 
return sideLength * sideLength 
} 
// overriding super's method 
override func simpleDescription() -> String { 
return "A square with sides of length (sideLength)." 
} 
}
getter/setter 
! 
class EquilateralTriangle: NamedShape { 
var sideLength: Double = 0.0 
init(sideLength: Double, name: String) { 
self.sideLength = sideLength 
super.init(name: name) 
numberOfSides = 3 
} 
! 
// getter / setter 
var perimeter: Double { 
get { 
return 3.0 * sideLength 
} 
set { 
sideLength = newValue / 3.0 
} 
} 
override func simpleDescription() -> String { 
return "An equilateral triangle with sides of length (sideLength)." 
} 
}
Property Observers 
! 
class StepCounter { 
var totalSteps: Int = 0 { 
willSet(newTotalSteps) { 
println("About to set totalSteps to (newTotalSteps)") 
} 
didSet { 
if totalSteps > oldValue { 
println("Added (totalSteps - oldValue) steps") 
} 
} 
} 
} 
! 
let stepCounter = StepCounter() 
stepCounter.totalSteps = 200 
// About to set totalSteps to 200 
// Added 200 steps
Enum and Struct
Enum 
• Enumerations can have methods! 
! 
enum Rank: Int { 
case Ace = 1 
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten 
case Jack, Queen, King 
func simpleDescription() -> String { 
switch self { 
case .Ace: return "ace" 
case .Jack: return "jack" 
case .Queen:return "queen" 
case .King: return "king" 
default: return String(self.toRaw()) 
} 
} 
}
Struct 
! 
struct Card { 
var rank: Rank 
var suit: Suit 
func simpleDescription() -> String { 
return "The (rank.simpleDescription()) of  
(suit.simpleDescription())" 
} 
} 
• Similar to Classes!! 
• Difference:! 
• Class: Reference type! 
• Struct: Value type
Protocols and Extensions
Protocols 
! 
protocol ExampleProtocol { 
var simpleDescription: String { get } 
mutating func adjust() 
} 
• In addition to classes, enumerations and 
structs can adopt protocols!
Protocols 
struct SimpleStructure: ExampleProtocol { 
var simpleDescription: String = "A simple structure" 
mutating func adjust() { 
simpleDescription += " (adjusted)" 
} 
} 
! 
class SimpleClass: ExampleProtocol { 
var simpleDescription: String = "A very simple class." 
var anotherProperty: Int = 69105 
func adjust() { 
simpleDescription += " Now 100% adjusted." 
} 
} 
• mutating keyword means methods modify structure 
• Class doesn’t need its methods marked as mutating keyword
Extensions 
• Similar to Categories in Objective-C 
! 
extension SomeType { 
// new functionality to add to SomeType goes here 
} 
! 
extension SomeType: SomeProtocol, AnotherProtocol { 
// implementation of protocol requirements goes here 
}
Generics 
• Generics is Template in C++ 
• Much of the Swift standard library is built with generic code 
! 
func repeat<ItemType>(item: ItemType, times: Int) -> [ItemType] { 
var result = [ItemType]() 
for i in 0..<times { 
result += item 
} 
return result 
} 
repeat("knock", 4)
Wrap Up 
• Looking through basic Swift features 
• Non Objective-C can get familiar, maybe. 
• To Learn Swift, 
check out The Swift Programming Language. 
https://developer.apple.com/library/ios/ 
documentation/Swift/Conceptual/ 
Swift_Programming_Language/
Thank you!

More Related Content

What's hot

Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
Jared Roesch
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
Alexis Gallagher
 
Introduction to Swift 2
Introduction to Swift 2Introduction to Swift 2
Introduction to Swift 2
Joris Timmerman
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
Nikita Popov
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
Shahjahan Samoon
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
Giuseppe Arici
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
Tran Khoa
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
Simon Willison
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
Alfonso Ruzafa
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
Ayesh Karunaratne
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
Peter Maas
 

What's hot (20)

Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Introduction to Swift 2
Introduction to Swift 2Introduction to Swift 2
Introduction to Swift 2
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
PHP 8.1 - What's new and changed
PHP 8.1 - What's new and changedPHP 8.1 - What's new and changed
PHP 8.1 - What's new and changed
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 

Similar to Quick swift tour

kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
02basics
02basics02basics
02basics
Waheed Warraich
 
NSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftNSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to Swift
Andreas Blick
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
Fatih Nayebi, Ph.D.
 
Javascript
JavascriptJavascript
Javascript
Sunil Thakur
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
openak
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan Samoon
 
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
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
Mohamed Wael
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kirill Rozov
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
Universe41
 
fundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.pptfundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.ppt
dejen6
 
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
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
Vladislav Hadzhiyski
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
Shimi Bandiel
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
Akash Pandey
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
zone
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
Bernard Loire
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
birbal
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 

Similar to Quick swift tour (20)

kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
02basics
02basics02basics
02basics
 
NSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftNSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to Swift
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 
Javascript
JavascriptJavascript
Javascript
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
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)
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
 
fundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.pptfundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.ppt
 
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...
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 

Recently uploaded

GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
Ortus Solutions, Corp
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
Fwdays
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
leebarnesutopia
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
Sunil Jagani
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 

Recently uploaded (20)

GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 

Quick swift tour

  • 2. Swift Language • Fast! • Modern! • Safe! • Interactive
  • 3. Fast • Swift code is compiled and optimised by the advanced LLVM compiler • ARM and x86-64 native code • Tuned native collections • Swift-specific optimiser • C-like procedural performance
  • 4. Modern • Clean syntax! • No headers! • No semicolons ! • Multiple return values! • Optional arguments ! • Closures! • Generics
  • 5. Safe • Type safety with type inference! • No uninitialized data! • Array bounds checks! • Restricts direct access to pointers! • Automatically manages memory using ARC
  • 6. Interactive • REPL • Playgrounds
  • 8. • Variable and Constant! • String! • Array, Dictionary! • Optionals! • Control Flow! • Function / Closure! • Class! • Enum / Struct! • Protocol / Extension! • Generics
  • 9. Variables / Constants ! // variable var myVariable = 42 myVariable = 50 ! // constant let myConstant = 42 //myConstant = 1 <- compile error ! ! // How to specify type var age: Int = 34 let distance: Double = 2.0
  • 10. String ! let age = 34 let label = "Age: " ! ! // Values are never implicitly converted to another type. let desc1 = label + String(age) ! // Simpler way with a backslash() let desc2 = "Age: (age)”
  • 11. Array, Dictionary ! // Create arrays and dictionaries using brackets ([]) ! // Array var iOSMembers = ["ichinose", "hato", "horimi", "tasaka", "watanabe"] ! // Dictionary let appMember = ["ios": iOSMembers] ! ! // Use initializer syntax to create an empty array or dictionary var emptyArray = [String]() var emptyDict = [String: Int]()
  • 13. nil in Swift • Swift’s nil is not the same as nil in Objective-C. In Swift, nil cannot be set to variables and constants… ! var value: Int = 10 value = nil // compile error let value1: String = nil // compile error • Objective-C: nil is a pointer to a nonexistent object. • Swift: nil is the absence of a value.
  • 14. Optionals • Optionals indicate that a constant or variable is allowed to have “no value” ! var serverResponseCode: Int? = 404 // serverResponseCode contains an actual Int value of 404 ! serverResponseCode = nil // serverResponseCode now contains no value ! // When no default value is set, // surveyAnswer is automatically set to nil var surveyAnswer: String?
  • 15. If Statements and Forced Unwrapping ! let optionalValue: Int? = 10 ! // (==) and (!=) can be used for nil check if optionalValue != nil { // Use "!" to access underlying value of optionalValue println("optionalValue has an integer value of (optionalValue!).") }
  • 16. Implicitly Unwrapped Optional • Placing an exclamation mark (String!) rather than a question mark (String?) • Useful when an optional value will always have a value • No need to check and unwrap the optional’s value every time it is accessed ! let possibleString: String? = "An optional string." ! // requires an exclamation mark let forcedString: String = possibleString! !! let assumedString: String! = "An implicitly unwrapped optional string." ! // no need for an exclamation mark let implicitString: String = assumedString
  • 18. for ! var firstForLoop = 0 for i in 0...3 { // equal to 0..<4 firstForLoop += i } !! let interestingNumbers = [ "Prime": [2, 3, 5, 7, 11, 13], "Fibonacci": [1, 1, 2, 3, 5, 8], ] var largest = 0 // key and value can be passed for (kind, numbers) in interestingNumbers { for number in numbers { if number > largest { largest = number } } }
  • 19. switch ! let value: Int = 10 switch value { case 0: println("(value)") case 1..<3: // range comparison println("(value)") case 4, 5: println("(value)") default: println("(value)") } • Flexible matching patterns • No break • default must appear last
  • 20. switch • switch are NOT limited to integers! ! let vegetable = "red pepper” ! var vegetableComment: String switch vegetable { case "celery": vegetableComment = "Add some raisins and make ants on a log.” ! case "cucumber", "watercress": vegetableComment = "That would make a good tea sandwich." ! case let x where x.hasSuffix("pepper"): vegetableComment = "Is it a spicy (x)?" ! default: vegetableComment = "Everything tastes good in soup." }
  • 22. Functions func sayHello(personName: String) -> String { let greeting = "Hello, " + personName + "!" return greeting } ! sayHello("Ameba")
  • 23. Functions • Functions are first-class type. // return value func makeIncrementer() -> (Int -> Int) { func addOne(number: Int) -> Int { return 1 + number } return addOne } ! // argument func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, lessThanTen)
  • 24. Closures • Similar to blocks in Objective-C! • Simple Syntax ! // Closure Expression Syntax { (parameters) -> return type in statements } ! // e.g. let names = ["horimi", "ichinose", "watanabe", "hato", "tasaka"] var reversed = sorted(names, { (s1: String, s2: String) -> Bool in return s1 > s2 })
  • 25. Closures ! // Inferring Type From Context reversed = sorted(names, { s1, s2 in return s1 > s2 } ) ! // Implicit Returns from Single-Expression Closures reversed = sorted(names, { s1, s2 in s1 > s2 } ) ! // Shorthand Argument Names reversed = sorted(names, { $0 > $1 } )
  • 26. Class
  • 27. Class ! class NamedShape { // properties var numberOfSides: Int = 0 var name: String // initializer init(name: String) { self.name = name } // method func simpleDescription() -> String { return "A shape with (numberOfSides) sides." } }
  • 28. Inheritance ! class Square: NamedShape { var sideLength: Double ! // initializer init(sideLength: Double, name: String) { // initialize before calling super.init self.sideLength = sideLength super.init(name: name) numberOfSides = 4 } func area() -> Double { return sideLength * sideLength } // overriding super's method override func simpleDescription() -> String { return "A square with sides of length (sideLength)." } }
  • 29. getter/setter ! class EquilateralTriangle: NamedShape { var sideLength: Double = 0.0 init(sideLength: Double, name: String) { self.sideLength = sideLength super.init(name: name) numberOfSides = 3 } ! // getter / setter var perimeter: Double { get { return 3.0 * sideLength } set { sideLength = newValue / 3.0 } } override func simpleDescription() -> String { return "An equilateral triangle with sides of length (sideLength)." } }
  • 30. Property Observers ! class StepCounter { var totalSteps: Int = 0 { willSet(newTotalSteps) { println("About to set totalSteps to (newTotalSteps)") } didSet { if totalSteps > oldValue { println("Added (totalSteps - oldValue) steps") } } } } ! let stepCounter = StepCounter() stepCounter.totalSteps = 200 // About to set totalSteps to 200 // Added 200 steps
  • 32. Enum • Enumerations can have methods! ! enum Rank: Int { case Ace = 1 case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten case Jack, Queen, King func simpleDescription() -> String { switch self { case .Ace: return "ace" case .Jack: return "jack" case .Queen:return "queen" case .King: return "king" default: return String(self.toRaw()) } } }
  • 33. Struct ! struct Card { var rank: Rank var suit: Suit func simpleDescription() -> String { return "The (rank.simpleDescription()) of (suit.simpleDescription())" } } • Similar to Classes!! • Difference:! • Class: Reference type! • Struct: Value type
  • 35. Protocols ! protocol ExampleProtocol { var simpleDescription: String { get } mutating func adjust() } • In addition to classes, enumerations and structs can adopt protocols!
  • 36. Protocols struct SimpleStructure: ExampleProtocol { var simpleDescription: String = "A simple structure" mutating func adjust() { simpleDescription += " (adjusted)" } } ! class SimpleClass: ExampleProtocol { var simpleDescription: String = "A very simple class." var anotherProperty: Int = 69105 func adjust() { simpleDescription += " Now 100% adjusted." } } • mutating keyword means methods modify structure • Class doesn’t need its methods marked as mutating keyword
  • 37. Extensions • Similar to Categories in Objective-C ! extension SomeType { // new functionality to add to SomeType goes here } ! extension SomeType: SomeProtocol, AnotherProtocol { // implementation of protocol requirements goes here }
  • 38. Generics • Generics is Template in C++ • Much of the Swift standard library is built with generic code ! func repeat<ItemType>(item: ItemType, times: Int) -> [ItemType] { var result = [ItemType]() for i in 0..<times { result += item } return result } repeat("knock", 4)
  • 39. Wrap Up • Looking through basic Swift features • Non Objective-C can get familiar, maybe. • To Learn Swift, check out The Swift Programming Language. https://developer.apple.com/library/ios/ documentation/Swift/Conceptual/ Swift_Programming_Language/