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
Swift: Tuples and Functions
Search
Antonio Bello
November 16, 2014
Programming
0
61
Swift: Tuples and Functions
SwiftCrunch, Krakow, Nov 16, 2014
Antonio Bello
November 16, 2014
Tweet
Share
More Decks by Antonio Bello
See All by Antonio Bello
Slices of Swift
jeden
1
55
From Learning to Mastering
jeden
4
140
Other Decks in Programming
See All in Programming
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
120
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
260
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
170
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
310
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
120
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.2k
Macとオーディオ再生 2024/11/02
yusukeito
0
390
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
210
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
260
デザインパターンで理解するLLMエージェントの作り方 / How to develop an LLM agent using agentic design patterns
rkaga
9
1.4k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.1k
Jakarta EE meets AI
ivargrimstad
0
750
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
A designer walks into a library…
pauljervisheath
204
24k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
380
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
910
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
GraphQLとの向き合い方2022年版
quramy
43
13k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
How GitHub (no longer) Works
holman
310
140k
Transcript
Swi$ Tuples'and'Func-ons Antonio&Bello Freelancer Code%Ar(st,%Polyglot%Developer @ant_bello
What's'a'tuple? A"tuple"it's"an"anonymous"struct • it$can$contain$mul,ple$heterogeneous$values • values$can$be$named$or$anonymous
Return'mul*ple'values func quotientAndRemainder(# dividend: Int, # divisor: Int) -> (quotient:
Int, remainder: Int) { let quotient = dividend / divisor return (quotient: quotient, remainder: dividend - divisor * quotient) } let result = quotientAndRemainder( dividend: 59, divisor: 13)
Pass$parameters$to$func/ons$and$ methods func quotientAndRemainder(# dividend: Int, # divisor: Int) ->
(quotient: Int, remainder: Int) { let quotient = dividend / divisor return (quotient: quotient, remainder: dividend - divisor * quotient) } let params = (dividend: 61, divisor: 7) let result = quotientAndRemainder(params)
Func%on'arguments'and'return' values'are'tuples A"func'on"with"no"parameters"takes"an"empty"tuple" ():" func doNothing() {...}
Func%on'arguments'and'return' values'are'tuples A"func'on"returning"Void"actually"returns"an"empty" tuple"(): func doSomething() -> () {...}
Func%on'arguments'and'return' values'are'tuples A"func'on"expec'ng"one"parameter"and"returning"a" single"value"actually: • takes'a'tuple'with'one'value • returns'a'tuple'with'one'value func doSomething(value:
Int) -> (Int) { ... }
Use$Cases
Use$cases Collec&ng)parameters)before) func&on)call Without'tuples ... var dividend = 29 ...
var divisor = 3 ... let result = quotientAndRemainder( dividend: dividend, divisor: divisor)
Use$cases Collec&ng)parameters)before) func&on)call With%tuples var params: (dividend: Int, divisor: Int)
... params.dividend = 29 ... params.divisor = 3 ... let immutableParams = params let result = quotientAndRemainder(immutable)
Important! A"tuple"passed"to"a"func/on"must"be"immutable let immutableParams = params let result = quotientAndRemainder(immutableParams)
Use$cases Buffering)func,on)calls Some%Code...
Thank&You code%@%github/jeden Antonio&Bello @ant_bello