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
Solving Problems the Swift Way
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ash Furrow
July 05, 2014
Technology
8.8k
23
Share
Solving Problems the Swift Way
A presentation on solving problems in idiomatic Swift.
Ash Furrow
July 05, 2014
More Decks by Ash Furrow
See All by Ash Furrow
Migrating to React Native: A Long-Term Retrospective
ashfurrow
0
290
How Artsy Automates Team Culture
ashfurrow
0
3.3k
Building Custom TSLint Rules
ashfurrow
0
470
Circumventing Fear of the Unknown
ashfurrow
1
570
Building Better Software by Building Better Teams
ashfurrow
1
640
Building Open Source Communities
ashfurrow
0
950
Comparative Asynchronous Programming
ashfurrow
2
9.7k
Building Compassionate Software
ashfurrow
0
520
Swift, Briskly
ashfurrow
0
190
Other Decks in Technology
See All in Technology
AI時代における技術的負債への取り組み
codenote
1
1.4k
ハーネスエンジニアリングをやりすぎた話 ~そのハーネスは解体された~
gotalab555
4
1.6k
Data Hubグループ 紹介資料
sansan33
PRO
0
2.9k
Master Dataグループ紹介資料
sansan33
PRO
1
4.6k
AzureのIaC管理からログ調査まで、随所に役立つSkillsとCustom-Instructions / Boosting IaC and Log Analysis with Skills
aeonpeople
0
220
ネットワーク運用を楽にするAWS DevOps Agent活用法!! / 20260421 Masaki Okuda
shift_evolve
PRO
2
200
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
0
260
コミュニティ・勉強会を作るのは目的じゃない
ohmori_yusuke
0
120
Code Interpreter で、AIに安全に コードを書かせる。
yokomachi
0
7.1k
Choose your own adventure in agentic design patterns
glaforge
0
130
Do Vibe Coding ao LLM em Produção para Busca Agêntica - TDC 2026 - Summit IA - São Paulo
jpbonson
3
110
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
10
78k
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.8k
Done Done
chrislema
186
16k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
330
Building the Perfect Custom Keyboard
takai
2
730
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
160
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
710
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Navigating Weather and Climate Data
rabernat
0
170
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
380
The browser strikes back
jonoalderson
0
970
Transcript
Idiomatic Swift Ash Furrow @ashfurrow
None
1.Better ways to solve familiar problems using Swift 2.Everyone is
a beginner again 3.We should share what we learn
Problem-Solving
You are here You wanna be here “Problem Solving”
• It would be a shame not to take advantage
of these new tools and techniques • Let’s take a look at some examples
• Completely new concept of nil • Indicates “missing” value
• Replaces nil, Nil, NULL, CGRectNull, -1, NSNotFound, NSNull, etc • Haskell’s “Maybe” type • C#’s “Nullable Types” Optionals
• Works well with Swift’s compile-time type safety • Which
is awesome • No, seriously, awesome • Eliminates several classes of bugs • Don’t over-use optional types Optionals
let a = someFunction() //returns Int? if a != nil
{ // use a! } Optionals
let a = someFunction() //returns Int? if let b =
a { // do something with b } if let a = a { // do something with a } Optionals
• Tuples are compound values • They are lightweight, temporary
containers for multiple values • Those values can be named • Useful for functions with multiple return types Tuples
func calculate() -> (Bool, Int?) { // ... return (result,
errorCode) } Tuples
func calculate() -> (Bool, Int?) { // ... return (result,
errorCode) } ! let calculation = calculate() ! if (calculation.0) { // … } Tuples
func calculate() -> (Bool, Int?) { // ... return (result,
errorCode) } ! let calculation = calculate() let (result, _) = calculation ! if (result) { // … } Tuples
func calculate() -> (result: Bool, errorCode: Int?) { // ...
return (result: result, errorCode: errorCode) } ! let calculation = calculate() if (calculation.errorCode) { // ... } Tuples
for (key, value) in dictionary { // ... } Tuples
• New APIs shouldn’t use out parameters • eg: NSError
pointers • Really great for use in pattern-matching Tuples
• Borrowed from functional programming • Really useful in tail-recursive
functions • Like “switch” statements on steroids Pattern-Matching
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { switch (indexPath.section) { case
0: { switch (indexPath.row) { case 0: ... } } break; } } Pattern-Matching
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { switch (indexPath.section) { case
ASHLoginSection: { switch (indexPath.row) { case ASHLoginSectionUserNameRow: ... } } break; } } Pattern-Matching
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { switch (indexPath.section,
indexPath.row) { case (0, _): ... default: ... } } Pattern-Matching
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { switch (indexPath.section,
indexPath.row) { case (0, let row): ... default: ... } } Pattern-Matching
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { switch (indexPath.section,
indexPath.row) { case (0, let row) where row > 5: ... default: ... } } Pattern-Matching
struct IntList { var head: Int = 0 var tail:
IntList? } ! ... ! switch (list.head, list.tail) { case (let head, nil): //... case (let head, let tail): //... } Pattern-Matching
• Generics are common in other languages, like C# and
C++ • Using a generic type as a placeholder, we can infer the type of variables at compile- time • A part of Swift’s “safe by default” behaviour Generics
struct Stack<T> { var items = [T]() mutating func push(item:
T) { items.append(item) } mutating func pop() -> T { return items.removeLast() } } Generics
var stack = Stack<Int>() ! var stack = Stack<String>() !
var stack = Stack<Recipe>() Generics
struct Stack<T: Equatable> : Equatable { var items = [T]()
mutating func push(item: T) { items.append(item) } mutating func pop() -> T { return items.removeLast() } } ! func ==<T>(lhs: Stack<T>, rhs: Stack<T>) -> Bool { return lhs.items == rhs.items } Generics
• Use stacks whenever you want to define an abstract
data type structure • Whenever possible, don’t bind new data structures to existing ones • Use protocols for loose coupling Generics
• Optionals • Pattern-matching • Tuples • Generics
Everyone is a Beginner
• No one is an expert in Swift • This
can be kind of stressful • Relax Everyone is a Beginner
• The benefits outweighs the cost of learning • Depending
on your circumstance • Have your say Everyone is a Beginner
• The hardest thing is the most important thing •
Start Everyone is a Beginner
• Don’t be embarrassed to ask questions! • Try to
ask in public so others can benefit from the answer Everyone is a Beginner
• Let’s borrow ideas Everyone is a Beginner
• Community-based conventions and guidelines are still being established Everyone
is a Beginner
We Should Share What We Learn
• Conventions and guidelines are still in flux • There’s
an opportunity to significantly alter the future of iOS and OS X programming We Should Share What We Learn
• The demand for material on Swift is HUGE •
Great opportunity to get known We Should Share What We Learn
• When you teach, you learn We Should Share What
We Learn
• If we all share what we learn, we all
get smarter • Rising tides lift all boats We Should Share What We Learn
• Stack Overflow • Blogs • Tweets • Gists •
Open source • Radars We Should Share What We Learn
http://github.com/artsy/eidolon
1.Better ways to solve familiar problems using Swift 2.Everyone is
a beginner again 3.We should share what we learn
Let’s Make Better Mistakes Tomorrow
Thank you" @ashfurrow