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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
7.1k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.4k
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
640
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.6k
Webフレームワークの ベンチマークについて
yusukebe
0
180
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
9.1k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
Performance Engineering for Everyone
elenatanasoiu
0
240
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
180
JavaDoc 再入門
nagise
1
430
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
290
Featured
See All Featured
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
Automating Front-end Workflow
addyosmani
1370
210k
New Earth Scene 8
popppiees
3
2.4k
We Have a Design System, Now What?
morganepeng
55
8.2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Ruling the World: When Life Gets Gamed
codingconduct
0
270
Paper Plane (Part 1)
katiecoart
PRO
0
9.4k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
170
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.8k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
450
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