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
72
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
62
From Learning to Mastering
jeden
4
150
Other Decks in Programming
See All in Programming
AgentCoreとHuman in the Loop
har1101
5
240
dchart: charts from deck markup
ajstarks
3
990
今から始めるClaude Code超入門
448jp
8
8.8k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AI時代の認知負荷との向き合い方
optfit
0
160
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.2k
Basic Architectures
denyspoltorak
0
670
CSC307 Lecture 08
javiergs
PRO
0
670
CSC307 Lecture 03
javiergs
PRO
1
490
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1k
Fragmented Architectures
denyspoltorak
0
160
高速開発のためのコード整理術
sutetotanuki
1
400
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
50
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
100
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Mobile First: as difficult as doing things right
swwweet
225
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Ethics towards AI in product and experience design
skipperchong
2
190
What's in a price? How to price your products and services
michaelherold
247
13k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
180
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
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