2009-2010: DU Profiles, the University of Denver's fact book
Introduction to Swift for Denver's Women Who Code
-
Upload
basel-farag -
Category
Science
-
view
70 -
download
5
Transcript of Introduction to Swift for Denver's Women Who Code
Who am I?
HI, I'm Basel
www.garglingwithrazorblades.com@BaselNotBasil
The theme of this talk will be: Swift &
’I don’t believe him when he says he has a
girlfriend.’
Why Swi!?
Swi! is Punk Rock.
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
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) }}
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)}
80
And now for a bit of golf.
SourcesAdvanced Swift by the ObjC.io crew
Swift Programming Language GuideDavid Waite
Beyonce