![Page 1: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/1.jpg)
Who am I?
![Page 2: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/2.jpg)
HI, I'm Basel
![Page 3: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/3.jpg)
www.garglingwithrazorblades.com@BaselNotBasil
![Page 4: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/4.jpg)
The theme of this talk will be: Swift &
’I don’t believe him when he says he has a
girlfriend.’
![Page 5: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/5.jpg)
Why Swi!?
![Page 6: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/6.jpg)
Swi! is Punk Rock.
![Page 7: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/7.jpg)
![Page 8: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/8.jpg)
![Page 9: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/9.jpg)
Sometimes you need to implement features that are only for experts who are building infrastructuree; those features should be clearly marked as
dangerous--not invitingly similar to features from other languages.
— Eric Lippert
![Page 10: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/10.jpg)
![Page 11: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/11.jpg)
![Page 12: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/12.jpg)
struct Item { var price: Int var count: Int}
class VendingMachine { var inventory = [ "Candy Bar": Item(price: 12, count: 7), "Chips": Item(price: 10, count: 4), "Pretzels": Item(price: 7, count: 11) ] var coinsDeposited = 0 func dispenseSnack(snack: String) { print("Dispensing \(snack)") }
func vend(itemNamed name: String) throws { guard let item = inventory[name] else { throw VendingMachineError.InvalidSelection }
guard item.count > 0 else { throw VendingMachineError.OutOfStock }
guard item.price <= coinsDeposited else { throw VendingMachineError.InsufficientFunds(coinsNeeded: item.price - coinsDeposited) }
coinsDeposited -= item.price
var newItem = item newItem.count -= 1 inventory[name] = newItem
dispenseSnack(name) }}
![Page 13: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/13.jpg)
let favoriteSnacks = [ "Alice": "Chips", "Bob": "Licorice", "Eve": "Pretzels",]func buyFavoriteSnack(person: String, vendingMachine: VendingMachine) throws { let snackName = favoriteSnacks[person] ?? "Candy Bar" try vendingMachine.vend(itemNamed: snackName)}
![Page 14: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/14.jpg)
![Page 15: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/15.jpg)
80
![Page 16: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/16.jpg)
And now for a bit of golf.
![Page 17: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/17.jpg)
![Page 18: Introduction to Swift for Denver's Women Who Code](https://reader034.vdocuments.us/reader034/viewer/2022050803/58ef845a1a28aba7498b45f5/html5/thumbnails/18.jpg)
SourcesAdvanced Swift by the ObjC.io crew
Swift Programming Language GuideDavid Waite
Beyonce