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
Emerging Best Practices in Swift
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ash Furrow
September 14, 2015
Programming
1.5k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Emerging Best Practices in Swift
Presented at iOSoho:
http://www.meetup.com/iOSoho/events/224796318/
Ash Furrow
September 14, 2015
More Decks by Ash Furrow
See All by Ash Furrow
My Slow Return to a Swift Career
ashfurrow
0
23
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
340
How Artsy Automates Team Culture
ashfurrow
0
3.4k
Building Custom TSLint Rules
ashfurrow
0
520
Circumventing Fear of the Unknown
ashfurrow
1
590
Building Better Software by Building Better Teams
ashfurrow
1
700
Building Open Source Communities
ashfurrow
0
1k
Comparative Asynchronous Programming
ashfurrow
2
9.8k
Building Compassionate Software
ashfurrow
0
580
Other Decks in Programming
See All in Programming
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
420
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
Press start. Python's next generation.
willingc
PRO
3
300
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
210
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
650
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
350
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
120
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
620
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.4k
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Building AI with AI
inesmontani
PRO
1
1.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
How to make the Groovebox
asonas
2
2.4k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Crafting Experiences
bethany
1
280
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
How GitHub (no longer) Works
holman
316
150k
Building Applications with DynamoDB
mza
96
7.2k
Test your architecture with Archunit
thirion
2
2.4k
Transcript
Emerging Best Practices in Swift Ash Furrow
None
I was Afraid That we'd just write Objective-C in Swift
syntax.
Everything turned out Fine
Today, we're exploring best practices in Swift.
We've been here before. Swift 2 is significantly different. Always
be learning.
Let's Go
Those who don't know history are doomed to repeat it.
— Lots of people.
Wrong.
Those who don't know the past can't make informed decisions
about the present. — Me
iOS 5 or Earlier? Let's see a show of hands.
Before Object Literals NSArray *array = [NSArray arrayWithObjects: @"This", @"is",
@"so", @"tedious", nil]; NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"Who would do this?", @"Not me", nil]; NSNumber *number = [NSNumber numberWithInt: 401];
Before Object Literals and ARC NSArray *array = [[NSArray arrayWithObjects:
@"This", @"is", @"so", @"tedious", nil] retain]; NSDictionary *dictionary = [[NSDictionary dictionaryWithObjectsAndKeys: @"Who would do this?", @"Not me", nil] retain]; NSNumber *number = [[NSNumber numberWithInt: 401] retain];
!
After Object Literals NSArray *array = @[ @"This", @"is", @"much",
@"better" ]; NSDictionary *dictionary = @{ @"Who likes this?": @"Me!" }; NSNumber *number = @(401);
Adopted immediately. Clearly better. Became a best practice.
Blocks — iOS 4 introduced blocks and GCD. — Adopted...
eventually. — Required new ideas. — Became a best practice.
Blocks — iOS 4 introduced blocks and GCD. — Adopted...
eventually. — Required new ideas. — Became a best practice. — Blocks now enable other best practices.
Swift 2
Swift 2 — Lots of new syntax. — New syntax
lets us do cool new things. — Like blocks, syntax is only a tool.
Swift 2 — guard — defer — throws — etc...
Should I use guard?
What can I do with guard?
Examples
If Overload if let thing = optionalThing { if thing.shouldDoThing
{ if let otherThing = thing.otherThing { doStuffWithThing(otherThing) } } }
where to the rescue if let thing = optionalThing, let
otherThing = thing.otherThing where thing.shoudDoThing { doStuffWithThing(otherThing) }
where to the rescue if let thing = optionalThing, let
otherThing = thing.otherThing where thing.shoudDoThing { doStuffWithThing(otherThing) } if...where isn't cool. You know what's cool?
where to the rescue if let thing = optionalThing, let
otherThing = thing.otherThing where thing.shoudDoThing { doStuffWithThing(otherThing) } if...where isn't cool. You know what's cool? ... Neither do I. Let's look together!
Avoid mutability func strings(parameter: [String], startingWith prefix: String) -> [String]
{ var mutableArray = [String]() for string in parameter { if string.hasPrefix(prefix) { mutableArray.append(string) } } return mutableArray }
Avoid mutability func strings(parameter: [String], startingWith prefix: String) -> [String]
{ var mutableArray = [String]() for string in parameter { if string.hasPrefix(prefix) { mutableArray.append(string) } } return mutableArray } That's silly.
Avoid mutability func strings(parameter: [String], startingWith prefix: String) -> [String]
{ return parameter.filter { $0.hasPrefix(prefix) } }
Extract associated values 1. Use Swift enums. 2. Attach associated
values. 3. Extract using case.
Extract associated values enum Result<T> { case Success(T) case Failure(reason:
String) } ... switch doThing() { case .Success: print("!") case .Failure(let reason): print("Oops: \(reason)") }
Extract associated values if case .Success = doThing() { print("!")
}
That's all just syntax.
Protocol-Oriented Programming
Just go watch the WWDC video.
Syntax itself is not a best practice. The patterns enabled
by syntax are what really matter. We need to discover them.
Learning !
Learning shouldn't just happen during the Xcode betas.
Learning is a constant activity, a state of mind.
Learning — Look for code smells. — Ask yourself how
you'd solve something differently. — Pick a Swift feature, ask "what could I do with this?" — Be comfortable throwing code away.
What about other communities? I bet they have good ideas,
too...
You should write a Blog
Wrap-up
We have a history of being awesome, let's keep it
up. Re-evaluate solutions to familiar problems. Always be learning. Also, write a blog.
Make better mistakes tomorrow.