Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
O que há de novo no Swift 2.0
Search
Francesco
June 30, 2015
Programming
0
52
O que há de novo no Swift 2.0
Apresentação no CocoaHeads Campinas em Junho de 2015
Francesco
June 30, 2015
Tweet
Share
More Decks by Francesco
See All by Francesco
Testando o App do Nubank - TDC Florianópolis 2019
fpg1503
2
250
Testando o App do Nubank - CocoaHeads
fpg1503
2
250
Garantindo qualidade no app do Nubank
fpg1503
0
150
Testando o App do Nubank
fpg1503
1
110
Testes na Prática
fpg1503
0
71
What's good code and How do I write it?
fpg1503
0
150
Emojicode
fpg1503
0
230
A coisa mais sensacional que passou despercebida na WWDC
fpg1503
0
330
Optionals e o Gato de Schrödinger
fpg1503
0
170
Other Decks in Programming
See All in Programming
RailsGirls IZUMO スポンサーLT
16bitidol
0
190
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
170
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1k
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
770
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
510
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
150
Goで作る、開発・CI環境
sin392
0
230
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
10
5.2k
Is Xcode slowly dying out in 2025?
uetyo
1
270
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
260
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
生成AI時代のコンポーネントライブラリの作り方
touyou
1
220
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
1.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Six Lessons from altMBA
skipperchong
28
3.9k
Faster Mobile Websites
deanohume
307
31k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Building an army of robots
kneath
306
45k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
The World Runs on Bad Software
bkeepers
PRO
69
11k
The Cult of Friendly URLs
andyhume
79
6.5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Transcript
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