Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
O que há de novo no Swift 2.0
Search
Francesco
June 30, 2015
Programming
65
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
O que há de novo no Swift 2.0
Apresentação no CocoaHeads Campinas em Junho de 2015
Francesco
June 30, 2015
Transcript
37 slides
What's new in Swift 2.0 by Francesco Perrotti-Garcia
Francesco Perrotti-Garcia iOS Developer @fpg1503 PlayKids - Movile
None
None
Swift 2.0
Open Source
What's new in Swfit Session 106 - 2015
Bacon
Analytics func myAnalyticsLogger<T>(value: T) { print(value) } Estado da Comida
enum FoodState { case Raw, Fried, Cooked(Cooker) }
Mas, o que é um Cooker?
Cooker enum Cooker : CookerType { case Oven, Microwave, Stove
} CookerType protocol CookerType { func cook(Food) }
Meu primeiro Cooker extension Cooker { func cook(food: Food) {
food.state = .Cooked(self) myAnalyticsLogger("Just cooked a \(food.state)\ \(food.name) using a \(self)") } }
Comida class Food { var state: FoodState var name: String
init(name: String, state: FoodState) { self.name = name self.state = state myAnalyticsLogger("Just created a \(state) \(name)") } }
Podemos criar Bacon!
Bacon class Bacon : Food { let tasty = true
} Meu bacon let myBacon = Bacon(name: "!", state: .Raw) //Just created a FoodState.Raw !
❤
Enums · Reflection · Carregam representação textual · Either<T1, T2>
funciona · Podem ser recursivos (no more Boxes) · indirect
Enums recursivos Futuramente enum Tree<T> { case Leaf(T) inidirect case
Node(Tree, Tree) } Pull Requests are welcome :)
Escopos arbitrários do { let myTemporaryMicrowave = Cooker.Microwave var myTemporaryBacon
= Bacon(name: "bacon", state: .Raw) myTemporaryMicrowave.cook(myTemporaryBacon) } //myTemporaryBacon não existe mais Consigo restringir mutabilidade
Outras mudanças Antes: do {} while Agora: repeat{} while ·
Options sets funcionam como tipos nativos!
Melhorias compilador · Funções e métodos · Novos warnings ·
var --> let · Ignorar resultado de método funcional
Melhorias para teste · Adição de @testable Documentação · Suporte
a Markdown
Cooker Melhorado Guard statements + pattern matching! extension Cooker {
func cook(food: Food) { guard case .Raw = food.state else { myAnalyticsLogger("Attempted to cook \(food.state)\ \(food.name) using \(self)") return } food.state = .Cooked(self) myAnalyticsLogger("Just cooked a \(food.state)\ \(food.name) using a \(self)") } }
Pattern matching everywhere · guard case · if case ·
for case Loops com filtro · for in... where filter
Melhorando Cooker Usando protocol extensions extension CookerType { func cook(food:
Food) { guard case .Raw = food.state else { myAnalyticsLogger("Attempted to cook \(food.state)\ \(food.name) using \(self)") return } food.state = .Cooked(self) myAnalyticsLogger("Just cooked a \(food.state)\ \(food.name) using a \(self)") } }
Usando o protocolo em FoodState enum FoodState { case Raw,
Fried, Cooked(CookerType) }
Criando um forno mais complexo struct Oven : CookerType {
var temperature : Float var heatOn : Bool func turnOn() { self.heatOn = true } func turnOff() { self.heatOn = false } }
Criando um forno mais complexo (que funciona) struct Oven :
CookerType { var temperature : Float var heatOn : Bool mutating func turnOn() { self.heatOn = true } mutating func turnOff() { self.heatOn = false } }
struct Oven : CookerType { ... mutating func cook(food: Food)
{ self.turnOn() guard case .Raw = food.state else { myAnalyticsLogger("Attempted to cook \(food.state)\ \(food.name) using \(self)") return } food.state = .Cooked(self) myAnalyticsLogger("Just cooked a \(food.state) \(food.name) using a\ \(self) at \(temperature) degrees") self.turnOff() } }
Defer ou como não colocar fogo na casa struct Oven
: CookerType { ... mutating func cook(food: Food) { self.turnOn() defer { self.turnOff() } guard case .Raw = food.state else { myAnalyticsLogger("Attempted to cook \(food.state)\ \(food.name) using \(self)") return } food.state = .Cooked(self) myAnalyticsLogger("Just cooked a \(food.state) \(food.name) using a\ \(self) at \(temperature) degrees") } }
Availability Antes respondsToSelector · descobrir selector (Objective-C) · não seguro
· pode dar falso positivo
Availability Agora · compilador checa · estático · lindo #available(iOS
9.0, *)
Protocol Extensions · extremamente poderoso · funcional mais natural ·
protocol-oriented programming
Protocol Oriented Programming in Swift Session 408 - 2015
Error handling · Erros triviais --> Optionals · Erros irrecuperáveis
--> throw · Erros não devem ser ignorados · Chega de error:nil
Error handling · try · do {} catch · try!
· NSError conforms com ErrorType · leves
Obrigado Dúvidas? github.com/fpg1503/Presentations
More Decks by Francesco
See All by Francesco
Testando o App do Nubank - TDC Florianópolis 2019
fpg1503
2
290
Testando o App do Nubank - CocoaHeads
fpg1503
2
290
Garantindo qualidade no app do Nubank
fpg1503
0
190
Testando o App do Nubank
fpg1503
1
150
Testes na Prática
fpg1503
0
110
What's good code and How do I write it?
fpg1503
0
190
Emojicode
fpg1503
0
270
A coisa mais sensacional que passou despercebida na WWDC
fpg1503
0
410
Optionals e o Gato de Schrödinger
fpg1503
0
200
Other Decks in Programming
See All in Programming
仕様駆動開発入門 (何を作るかを先に決めて渡す) | 目指せ Kiro マスター 05
inariku
PRO
3
220
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
630
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
130
エージェントの管理もエージェントに – herdr-core と自作バックログで作る司令塔 –
nearme_tech
PRO
2
130
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
Crash Auto Pipelines
veronikapj
1
450
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
330
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
340
Debian JP Projectのサーバー構成
uwabami
1
180
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
120
Featured
See All Featured
The agentic SEO stack - context over prompts
schlessera
0
1k
The Language of Interfaces
destraynor
162
27k
So, you think you're a good person
axbom
PRO
2
2.3k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Design in an AI World
tapps
1
400
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
540
Mobile First: as difficult as doing things right
swwweet
225
10k
Navigating Weather and Climate Data
rabernat
0
600
GraphQLとの向き合い方2022年版
quramy
50
15k
Site-Speed That Sticks
csswizardry
13
1.6k
Designing for Performance
lara
612
70k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k