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
57
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
More Decks by Francesco
See All by Francesco
Testando o App do Nubank - TDC Florianópolis 2019
fpg1503
2
280
Testando o App do Nubank - CocoaHeads
fpg1503
2
280
Garantindo qualidade no app do Nubank
fpg1503
0
180
Testando o App do Nubank
fpg1503
1
140
Testes na Prática
fpg1503
0
100
What's good code and How do I write it?
fpg1503
0
180
Emojicode
fpg1503
0
260
A coisa mais sensacional que passou despercebida na WWDC
fpg1503
0
390
Optionals e o Gato de Schrödinger
fpg1503
0
190
Other Decks in Programming
See All in Programming
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
550
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
130
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.8k
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
540
継続モナドとリアクティブプログラミング
yukikurage
3
680
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
210
React本体のコードリーディング
high_g_engineer
1
130
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
250
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
740
AIが無かった頃の素敵な出会いの話
codmoninc
1
360
Google Apps Script で Ruby を動かす
kawahara
0
130
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
180
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
360
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
330
Being A Developer After 40
akosma
91
590k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
420
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
500
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