SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
Swift Thinking
@NatashaTheRobot
Back to December
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
}
println("Hello, World!")
—Optionals?!
—Value Types
—Higher-order functions
Optionals?!
"~40% of bugs shipped to
customers in the last
three years would have
been caught immediately
by using Swift" - Sunset
Lake Software
enum Optional<T> {
case Some(T)
case None
}
let tSwiftAlbums = [
2014 : "1989",
2012: "Red",
2010: "Speak Now",
2008: "Fearless",
2006: "Taylor Swift"]
let possibleAlbumFrom2011: String? = tSwiftAlbums[2011]
let possibleAlbumFrom2014: String? = tSwiftAlbums[2014]
let tSwiftAlbums = [
2014 : "1989",
2012: "Red",
2010: "Speak Now",
2008: "Fearless",
2006: "Taylor Swift"]
let possibleAlbumFrom2014: String? = tSwiftAlbums[2014]
if possibleAlbumFrom2014 == .None {
println("Taylor Swift had no albums in 2014")
} else {
let albumFrom2014 = possibleAlbumFrom2014!
println("Taylor Swift's 2014 album was (albumFrom2014)")
}
let tSwiftAlbums = [
2014 : "1989",
2012: "Red",
2010: "Speak Now",
2008: "Fearless",
2006: "Taylor Swift"]
if let albumFor2014 = tSwiftAlbums[2014] {
println("Taylor Swift's 2014 album was (albumFor2014)")
} else {
println("Taylor Swift had no albums in 2014")
}
Value Types
—structs
—enums
—(tuples)
class Album {
let title: String
let artist: String
var copiesSold: Int
init(title: String, artist: String, copiesSold: Int) {
self.title = title
self.artist = artist
self.copiesSold = copiesSold
}
}
let tSwift1989 = Album(title: "1989",
artist: "Taylor Swift",
copiesSold: 4505000)
func another1000Sales(forAlbum album: Album) {
album.copiesSold += 1000
}
another1000Sales(forAlbum: tSwift1989)
tSwift1989.copiesSold // 4,506,000
struct Album {
let title: String
let artist: String
var copiesSold: Int
}
let tSwift1989 = Album(title: "1989",
artist: "Taylor Swift",
copiesSold: 4505000)
func another1000Sales(var forAlbum album: Album) {
album.copiesSold += 1000
album.copiesSold // 4,506,000
}
another1000Sales(forAlbum: tSwift1989)
tSwift1989.copiesSold // 4,505,000
Use a value type when:
—Comparing instance data with == makes sense
—You want copies to have independent state
—The data will be used in code across multiple
threads
Swift Blog: Value and Reference Types
Use a reference type (e.g. use a class) when:
—Comparing instance identity with == makes sense
—You want to create shared, mutable state
Swift Blog: Value and Reference Types
"Almost all types in Swift are value
types, including arrays,
dictionaries, numbers, booleans,
tuples, and enums. Classes are the
exception rather than the rule." -
Functional Swift Book
$ grep -e "^struct " swift.md | wc -l
81
$ grep -e "^enum " swift.md | wc -l
8
$ grep -e "^class " swift.md | wc -l
3
Higher-order Functions
a higher-order function is a function that does at
least one of the following:
—takes one or more functions as an input
—outputs a function
- Wikipedia
Array
—map
—reduce
â€”ïŹlter
â€”ïŹ‚atMap
struct Song {
let title: String
let album: String
}
let tSwiftSongs = [
Song(title: "Blank Space", album: "1989"),
Song(title: "All You Had to Do Was Stay", album: "Red"),
Song(title: "Back to December", album: "Speak Now"),
Song(title: "All You Had to Do Was Stay", album: "1989"),
Song(title: "Begin Again", album: "Red"),
Song(title: "Clean", album: "1989"),
Song(title: "Love Story", album: "Fearless"),
Song(title: "Shake It Off", album: "1989"),
Song(title: "Bad Blood", album: "1989")
]
struct tSwift1989Album {
let title = "1989"
var songs = [Song]()
}
class tSwift1989Album {
let title = "1989"
var songs = [Song]()
func add1989Songs() {
for song in tSwiftSongs {
if song.album == "1989" {
songs.append(song)
}
}
}
}
let album = tSwift1989Album()
album.add1989Songs()
album.songs.count // 5
let album = tSwift1989Album()
album.add1989Songs()
album.songs.count // 5
// MUCH FURTHER DOWN
album.add1989Songs()
let album = tSwift1989Album()
album.add1989Songs()
album.songs.count // 5
// MUCH FURTHER DOWN
album.add1989Songs()
album.songs.count // 10
let album = tSwift1989Album()
album.add1989Songs()
album.songs.count // 5
album.add1989Songs()
album.songs.count // 10
album.add1989Songs()
album.songs.count // 15
album.add1989Songs()
album.songs.count // 20
/// Return an `Array` containing the elements `x` of `self` for which
/// `includeElement(x)` is `true`
func filter(includeElement: (T) -> Bool) -> [T]
class tSwift1989Album {
let title = "1989"
var songs = [Song]()
func add1989SongsWithFilter() {
songs = tSwiftSongs.filter({ song in song.album == "1989"})
}
}
songs = tSwiftSongs.filter({ song in song.album == "1989"})
songs = tSwiftSongs.filter({ song in song.album == "1989"})
songs = tSwiftSongs.filter({ $0.album == "1989"})
songs = tSwiftSongs.filter({ song in song.album == "1989"})
songs = tSwiftSongs.filter({ $0.album == "1989"})
songs = tSwiftSongs.filter { $0.album == "1989"}
let album = tSwift1989Album()
album.add1989SongsWithFilter()
album.songs.count // 5
album.add1989SongsWithFilter()
album.songs.count // 5
album.add1989SongsWithFilter()
album.songs.count // 5
album.add1989SongsWithFilter()
album.songs.count // 5
album.add1989SongsWithFilter()
album.songs.count // 5
Swift Thinking
—Optionals?!
—Value Types
—Higher-order functions
Questions?!
@NatashaTheRobot

Weitere Àhnliche Inhalte

Andere mochten auch

Social media strategies slideshare version
Social media strategies slideshare versionSocial media strategies slideshare version
Social media strategies slideshare versionKella Price
 
Proyecto final jonathan lara reyes
Proyecto final jonathan lara reyesProyecto final jonathan lara reyes
Proyecto final jonathan lara reyesJONLR
 
Three Things...
Three Things...Three Things...
Three Things...OH TEIK BIN
 
BAAL-SIG-LLT-2016-Programme-Booklet_FINAL
BAAL-SIG-LLT-2016-Programme-Booklet_FINALBAAL-SIG-LLT-2016-Programme-Booklet_FINAL
BAAL-SIG-LLT-2016-Programme-Booklet_FINALHelen Lee
 
State of open research data open con
State of open research data   open conState of open research data   open con
State of open research data open conAmye Kenall
 
Ű§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠ
Ű§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠŰ§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠ
Ű§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠabuomar75
 
ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ”
 ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ” ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ”
ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ”The International Association of Marketing Initiatives (IAMI)
 
Welding process
Welding processWelding process
Welding processDarawan Wahid
 
Workshop #14: Behaviour, government policy and me: applying behavioural insig...
Workshop #14: Behaviour, government policy and me: applying behavioural insig...Workshop #14: Behaviour, government policy and me: applying behavioural insig...
Workshop #14: Behaviour, government policy and me: applying behavioural insig...ux singapore
 
Multi-Omics Bioinformatics across Application Domains
Multi-Omics Bioinformatics across Application DomainsMulti-Omics Bioinformatics across Application Domains
Multi-Omics Bioinformatics across Application DomainsChristoph Steinbeck
 
Selling Account-Based Marketing (ABM) Internally To Your Organization
Selling Account-Based Marketing (ABM) Internally To Your OrganizationSelling Account-Based Marketing (ABM) Internally To Your Organization
Selling Account-Based Marketing (ABM) Internally To Your OrganizationHeinz Marketing Inc
 
How to Get Into Big Data: Women in Tech Philly
How to Get Into Big Data: Women in Tech PhillyHow to Get Into Big Data: Women in Tech Philly
How to Get Into Big Data: Women in Tech PhillyVicki Boykis
 
What Is Value Added For Security Guard Company Clients?
What Is Value Added For Security Guard Company Clients?What Is Value Added For Security Guard Company Clients?
What Is Value Added For Security Guard Company Clients?OfficerReports.com
 
100+ Best Quotes from Cannes Lions 2016
100+ Best Quotes from Cannes Lions 2016100+ Best Quotes from Cannes Lions 2016
100+ Best Quotes from Cannes Lions 2016Michael Boamah
 
Cibeles Madrid Fashion Week 2009
Cibeles Madrid Fashion Week 2009Cibeles Madrid Fashion Week 2009
Cibeles Madrid Fashion Week 2009Compulsiva Accesorios
 

Andere mochten auch (18)

Social media strategies slideshare version
Social media strategies slideshare versionSocial media strategies slideshare version
Social media strategies slideshare version
 
Proyecto final jonathan lara reyes
Proyecto final jonathan lara reyesProyecto final jonathan lara reyes
Proyecto final jonathan lara reyes
 
Three Things...
Three Things...Three Things...
Three Things...
 
BAAL-SIG-LLT-2016-Programme-Booklet_FINAL
BAAL-SIG-LLT-2016-Programme-Booklet_FINALBAAL-SIG-LLT-2016-Programme-Booklet_FINAL
BAAL-SIG-LLT-2016-Programme-Booklet_FINAL
 
Control panel
Control panelControl panel
Control panel
 
State of open research data open con
State of open research data   open conState of open research data   open con
State of open research data open con
 
Ű§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠ
Ű§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠŰ§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠ
Ű§ŰšÙŠ Ù„Ű§ ŰȘكن ۳ۚۚ Ù‡Ù„Ű§ÙƒÙŠ
 
Qué tipo de compuesto es el agua
Qué tipo de compuesto es el aguaQué tipo de compuesto es el agua
Qué tipo de compuesto es el agua
 
ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ”
 ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ” ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ”
ĐąĐ”Ń…ĐœĐŸĐ»ĐŸĐłĐžĐž ĐČĐžŃ€Ń‚ŃƒĐ°Đ»ŃŒĐœĐŸĐč Đž ĐŽĐŸĐżĐŸĐ»ĐœĐ”ĐœĐœĐŸĐč Ń€Đ”Đ°Đ»ŃŒĐœĐŸŃŃ‚Đž ĐČ ĐŒĐ°Ń€ĐșĐ”Ń‚ĐžĐœĐłĐ” Đž рДĐșĐ»Đ°ĐŒĐ”
 
Welding process
Welding processWelding process
Welding process
 
Workshop #14: Behaviour, government policy and me: applying behavioural insig...
Workshop #14: Behaviour, government policy and me: applying behavioural insig...Workshop #14: Behaviour, government policy and me: applying behavioural insig...
Workshop #14: Behaviour, government policy and me: applying behavioural insig...
 
Multi-Omics Bioinformatics across Application Domains
Multi-Omics Bioinformatics across Application DomainsMulti-Omics Bioinformatics across Application Domains
Multi-Omics Bioinformatics across Application Domains
 
Selling Account-Based Marketing (ABM) Internally To Your Organization
Selling Account-Based Marketing (ABM) Internally To Your OrganizationSelling Account-Based Marketing (ABM) Internally To Your Organization
Selling Account-Based Marketing (ABM) Internally To Your Organization
 
How to Get Into Big Data: Women in Tech Philly
How to Get Into Big Data: Women in Tech PhillyHow to Get Into Big Data: Women in Tech Philly
How to Get Into Big Data: Women in Tech Philly
 
What Is Value Added For Security Guard Company Clients?
What Is Value Added For Security Guard Company Clients?What Is Value Added For Security Guard Company Clients?
What Is Value Added For Security Guard Company Clients?
 
100+ Best Quotes from Cannes Lions 2016
100+ Best Quotes from Cannes Lions 2016100+ Best Quotes from Cannes Lions 2016
100+ Best Quotes from Cannes Lions 2016
 
LinkedIn Ads Playbook
LinkedIn Ads PlaybookLinkedIn Ads Playbook
LinkedIn Ads Playbook
 
Cibeles Madrid Fashion Week 2009
Cibeles Madrid Fashion Week 2009Cibeles Madrid Fashion Week 2009
Cibeles Madrid Fashion Week 2009
 

Ähnlich wie Swift Thinking

Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdffazanmobiles
 
Intro toswift1
Intro toswift1Intro toswift1
Intro toswift1Jordan Morgan
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressionsBen Brumfield
 
What Are For Expressions in Scala?
What Are For Expressions in Scala?What Are For Expressions in Scala?
What Are For Expressions in Scala?BoldRadius Solutions
 
Can someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfCan someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfakshpatil4
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfarihanthtextiles
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular ExpressionsOCSI
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languagePawel Szulc
 
Programming in Vinyl (BayHac 2014)
Programming in Vinyl (BayHac 2014)Programming in Vinyl (BayHac 2014)
Programming in Vinyl (BayHac 2014)jonsterling
 

Ähnlich wie Swift Thinking (11)

Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
 
Intro toswift1
Intro toswift1Intro toswift1
Intro toswift1
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
What Are For Expressions in Scala?
What Are For Expressions in Scala?What Are For Expressions in Scala?
What Are For Expressions in Scala?
 
Can someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfCan someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdf
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdf
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
Programming in Vinyl (BayHac 2014)
Programming in Vinyl (BayHac 2014)Programming in Vinyl (BayHac 2014)
Programming in Vinyl (BayHac 2014)
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Snakes and ladders
Snakes and laddersSnakes and ladders
Snakes and ladders
 

Mehr von Natasha Murashev

Digital Nomad: The New Normal
Digital Nomad: The New NormalDigital Nomad: The New Normal
Digital Nomad: The New NormalNatasha Murashev
 
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POPNatasha Murashev
 
Build Features Not Apps
Build Features Not AppsBuild Features Not Apps
Build Features Not AppsNatasha Murashev
 
Build Features Not Apps
Build Features Not AppsBuild Features Not Apps
Build Features Not AppsNatasha Murashev
 
Practical Protocols with Associated Types
Practical Protocols with Associated TypesPractical Protocols with Associated Types
Practical Protocols with Associated TypesNatasha Murashev
 
The Secret Life of a Digital Nomad
The Secret Life of a Digital NomadThe Secret Life of a Digital Nomad
The Secret Life of a Digital NomadNatasha Murashev
 
How to Win on the Apple Watch
How to Win on the Apple WatchHow to Win on the Apple Watch
How to Win on the Apple WatchNatasha Murashev
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingNatasha Murashev
 
Protocol Oriented MVVM - Auckland iOS Meetup
Protocol Oriented MVVM - Auckland iOS MeetupProtocol Oriented MVVM - Auckland iOS Meetup
Protocol Oriented MVVM - Auckland iOS MeetupNatasha Murashev
 
Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Natasha Murashev
 
Protocol-Oriented MVVM
Protocol-Oriented MVVMProtocol-Oriented MVVM
Protocol-Oriented MVVMNatasha Murashev
 
The Zen Guide to WatchOS 2
The Zen Guide to WatchOS 2The Zen Guide to WatchOS 2
The Zen Guide to WatchOS 2Natasha Murashev
 
Using Parse in Hackathons
Using Parse in HackathonsUsing Parse in Hackathons
Using Parse in HackathonsNatasha Murashev
 
Unleash the Power of Playgrounds
Unleash the Power of PlaygroundsUnleash the Power of Playgrounds
Unleash the Power of PlaygroundsNatasha Murashev
 

Mehr von Natasha Murashev (20)

Digital Nomad: The New Normal
Digital Nomad: The New NormalDigital Nomad: The New Normal
Digital Nomad: The New Normal
 
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
 
Build Features Not Apps
Build Features Not AppsBuild Features Not Apps
Build Features Not Apps
 
Build Features Not Apps
Build Features Not AppsBuild Features Not Apps
Build Features Not Apps
 
Practical Protocols with Associated Types
Practical Protocols with Associated TypesPractical Protocols with Associated Types
Practical Protocols with Associated Types
 
The Secret Life of a Digital Nomad
The Secret Life of a Digital NomadThe Secret Life of a Digital Nomad
The Secret Life of a Digital Nomad
 
How to Win on the Apple Watch
How to Win on the Apple WatchHow to Win on the Apple Watch
How to Win on the Apple Watch
 
Hello watchOS2
Hello watchOS2 Hello watchOS2
Hello watchOS2
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
Protocol Oriented MVVM - Auckland iOS Meetup
Protocol Oriented MVVM - Auckland iOS MeetupProtocol Oriented MVVM - Auckland iOS Meetup
Protocol Oriented MVVM - Auckland iOS Meetup
 
Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)
 
Protocol-Oriented MVVM
Protocol-Oriented MVVMProtocol-Oriented MVVM
Protocol-Oriented MVVM
 
The Swift Architect
The Swift ArchitectThe Swift Architect
The Swift Architect
 
The Zen Guide to WatchOS 2
The Zen Guide to WatchOS 2The Zen Guide to WatchOS 2
The Zen Guide to WatchOS 2
 
HealthKit Deep Dive
HealthKit Deep DiveHealthKit Deep Dive
HealthKit Deep Dive
 
Using Parse in Hackathons
Using Parse in HackathonsUsing Parse in Hackathons
Using Parse in Hackathons
 
Hello, WatchKit
Hello, WatchKitHello, WatchKit
Hello, WatchKit
 
Hello, WatchKit
Hello, WatchKitHello, WatchKit
Hello, WatchKit
 
Unleash the Power of Playgrounds
Unleash the Power of PlaygroundsUnleash the Power of Playgrounds
Unleash the Power of Playgrounds
 
Hello, WatchKit
Hello, WatchKitHello, WatchKit
Hello, WatchKit
 

KĂŒrzlich hochgeladen

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂anilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto GonzĂĄlez Trastoy
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

KĂŒrzlich hochgeladen (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
 
Vip Call Girls Noida âžĄïž Delhi âžĄïž 9999965857 No Advance 24HRS Live
Vip Call Girls Noida âžĄïž Delhi âžĄïž 9999965857 No Advance 24HRS LiveVip Call Girls Noida âžĄïž Delhi âžĄïž 9999965857 No Advance 24HRS Live
Vip Call Girls Noida âžĄïž Delhi âžĄïž 9999965857 No Advance 24HRS Live
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Swift Thinking

  • 2. Back to December #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return 0; }
  • 4.
  • 5.
  • 6.
  • 7.
  • 10. "~40% of bugs shipped to customers in the last three years would have been caught immediately by using Swift" - Sunset Lake Software
  • 11.
  • 12. enum Optional<T> { case Some(T) case None }
  • 13. let tSwiftAlbums = [ 2014 : "1989", 2012: "Red", 2010: "Speak Now", 2008: "Fearless", 2006: "Taylor Swift"] let possibleAlbumFrom2011: String? = tSwiftAlbums[2011] let possibleAlbumFrom2014: String? = tSwiftAlbums[2014]
  • 14.
  • 15. let tSwiftAlbums = [ 2014 : "1989", 2012: "Red", 2010: "Speak Now", 2008: "Fearless", 2006: "Taylor Swift"] let possibleAlbumFrom2014: String? = tSwiftAlbums[2014] if possibleAlbumFrom2014 == .None { println("Taylor Swift had no albums in 2014") } else { let albumFrom2014 = possibleAlbumFrom2014! println("Taylor Swift's 2014 album was (albumFrom2014)") }
  • 16. let tSwiftAlbums = [ 2014 : "1989", 2012: "Red", 2010: "Speak Now", 2008: "Fearless", 2006: "Taylor Swift"] if let albumFor2014 = tSwiftAlbums[2014] { println("Taylor Swift's 2014 album was (albumFor2014)") } else { println("Taylor Swift had no albums in 2014") }
  • 17.
  • 20. class Album { let title: String let artist: String var copiesSold: Int init(title: String, artist: String, copiesSold: Int) { self.title = title self.artist = artist self.copiesSold = copiesSold } }
  • 21. let tSwift1989 = Album(title: "1989", artist: "Taylor Swift", copiesSold: 4505000) func another1000Sales(forAlbum album: Album) { album.copiesSold += 1000 } another1000Sales(forAlbum: tSwift1989) tSwift1989.copiesSold // 4,506,000
  • 22. struct Album { let title: String let artist: String var copiesSold: Int }
  • 23. let tSwift1989 = Album(title: "1989", artist: "Taylor Swift", copiesSold: 4505000) func another1000Sales(var forAlbum album: Album) { album.copiesSold += 1000 album.copiesSold // 4,506,000 } another1000Sales(forAlbum: tSwift1989) tSwift1989.copiesSold // 4,505,000
  • 24. Use a value type when: —Comparing instance data with == makes sense —You want copies to have independent state —The data will be used in code across multiple threads Swift Blog: Value and Reference Types
  • 25. Use a reference type (e.g. use a class) when: —Comparing instance identity with == makes sense —You want to create shared, mutable state Swift Blog: Value and Reference Types
  • 26. "Almost all types in Swift are value types, including arrays, dictionaries, numbers, booleans, tuples, and enums. Classes are the exception rather than the rule." - Functional Swift Book
  • 27. $ grep -e "^struct " swift.md | wc -l 81 $ grep -e "^enum " swift.md | wc -l 8 $ grep -e "^class " swift.md | wc -l 3
  • 29. a higher-order function is a function that does at least one of the following: —takes one or more functions as an input —outputs a function - Wikipedia
  • 31. struct Song { let title: String let album: String } let tSwiftSongs = [ Song(title: "Blank Space", album: "1989"), Song(title: "All You Had to Do Was Stay", album: "Red"), Song(title: "Back to December", album: "Speak Now"), Song(title: "All You Had to Do Was Stay", album: "1989"), Song(title: "Begin Again", album: "Red"), Song(title: "Clean", album: "1989"), Song(title: "Love Story", album: "Fearless"), Song(title: "Shake It Off", album: "1989"), Song(title: "Bad Blood", album: "1989") ]
  • 32. struct tSwift1989Album { let title = "1989" var songs = [Song]() }
  • 33. class tSwift1989Album { let title = "1989" var songs = [Song]() func add1989Songs() { for song in tSwiftSongs { if song.album == "1989" { songs.append(song) } } } }
  • 34. let album = tSwift1989Album() album.add1989Songs() album.songs.count // 5
  • 35. let album = tSwift1989Album() album.add1989Songs() album.songs.count // 5 // MUCH FURTHER DOWN album.add1989Songs()
  • 36. let album = tSwift1989Album() album.add1989Songs() album.songs.count // 5 // MUCH FURTHER DOWN album.add1989Songs() album.songs.count // 10
  • 37. let album = tSwift1989Album() album.add1989Songs() album.songs.count // 5 album.add1989Songs() album.songs.count // 10 album.add1989Songs() album.songs.count // 15 album.add1989Songs() album.songs.count // 20
  • 38. /// Return an `Array` containing the elements `x` of `self` for which /// `includeElement(x)` is `true` func filter(includeElement: (T) -> Bool) -> [T]
  • 39. class tSwift1989Album { let title = "1989" var songs = [Song]() func add1989SongsWithFilter() { songs = tSwiftSongs.filter({ song in song.album == "1989"}) } }
  • 40. songs = tSwiftSongs.filter({ song in song.album == "1989"})
  • 41. songs = tSwiftSongs.filter({ song in song.album == "1989"}) songs = tSwiftSongs.filter({ $0.album == "1989"})
  • 42. songs = tSwiftSongs.filter({ song in song.album == "1989"}) songs = tSwiftSongs.filter({ $0.album == "1989"}) songs = tSwiftSongs.filter { $0.album == "1989"}
  • 43. let album = tSwift1989Album() album.add1989SongsWithFilter() album.songs.count // 5 album.add1989SongsWithFilter() album.songs.count // 5 album.add1989SongsWithFilter() album.songs.count // 5 album.add1989SongsWithFilter() album.songs.count // 5 album.add1989SongsWithFilter() album.songs.count // 5
  • 44.