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
77
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swift: Tuples and Functions
SwiftCrunch, Krakow, Nov 16, 2014
Antonio Bello
November 16, 2014
More Decks by Antonio Bello
See All by Antonio Bello
Slices of Swift
jeden
1
70
From Learning to Mastering
jeden
4
160
Other Decks in Programming
See All in Programming
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
240
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
130
ふつうのFeature Flag実践入門
irof
8
4.2k
Inside Stream API
skrb
1
810
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
230
どこまでゆるくて許されるのか
tk3fftk
0
270
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
200
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
250
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
200
OSもどきOS
arkw
0
600
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Featured
See All Featured
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
260
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
620
Six Lessons from altMBA
skipperchong
29
4.3k
Facilitating Awesome Meetings
lara
57
7k
Docker and Python
trallard
47
3.9k
YesSQL, Process and Tooling at Scale
rocio
174
15k
New Earth Scene 8
popppiees
3
2.4k
Exploring anti-patterns in Rails
aemeredith
3
430
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
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