Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Generics With Swift
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
akira hirakawa
April 16, 2015
Programming
39
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Generics With Swift
for iOS meetup in Singapore
https://www.facebook.com/events/1018494251512074/
akira hirakawa
April 16, 2015
Other Decks in Programming
See All in Programming
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
Jetpack Compose Mechanisms
skydoves
3
820
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
310
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
The Cult of Friendly URLs
andyhume
79
7k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
Discover your Explorer Soul
emna__ayadi
2
1.3k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Transcript
Generics with Swift by akira hirakawa @akirahrkw
Do you Swift?
we use swift for Burpple app
None
Generics with Swift
Do you use Generics?
example
swap two Int values func swapTwoInts(inout a: Int, inout b:
Int) { let temporaryA = a a = b b = temporaryA }
swap two Double values func swapTwoDoubles(inout a: Double, inout b:
Double) { let temporaryA = a a = b b = temporaryA }
swap two String values func swapTwoStrings(inout a: String, inout b:
String) { let temporaryA = a a = b b = temporaryA }
these are identical !!
more useful more flexible?
generics !!
Generic function func swapTwoValues<T>(inout a: T, inout b: T) {
let temporaryA = a a = b b = temporaryA }
swap Int values var someInt = 3 var anotherInt =
107 swapTwoValues(&someInt, &anotherInt)
swap String values var someString = "hello" var anotherString =
"world" swapTwoValues(&someString, &anotherString)
can not var someInt = 3 var anotherString = "world"
swapTwoValues(&someInt, &anotherString)
useful flexible
but
why not use Protocol?
can
swap two Any values func swapTwoValues(inout a: Any, inout b:
Any) { let temporaryA = a a = b b = temporaryA }
var a = 1 as Any var b = 2
as Any swapTwoValues(&a, &b)
var a = “a” as Any var b = “b”
as Any swapTwoValues(&a, &b)
but
var a = 1 as Any var b = “a”
as Any swapTwoValues(&a, &b)
which is better?
what is the difference?
func executeProtocol(p: Printable) -> Printable { } func executeGenerics<T: Printable>(p:
T) -> T { }
almost same
func executProtocol(p: Printable) -> Printable { p.description return p }
func executeGenerics<T: Printable>(p: T) -> T { p.description return p }
no difference?
return value
func executProtocol(p: Printable) -> Printable { return p } func
executeGenerics<T: Printable>(p: T) -> T { return p }
-> Printable you need to cast to use the return
value var movie: Movie = … var p: Printable = executProtocol(movie) (p as Movie).show()
-> T you don’t need to cast to use the
value var movie: Movie = … movie = executeGenerics(movie) movie.show()
useful
different
performance?
case swap method:
case increment:
depends on -O and swift version
fast useful flexible
in practice?
case DataSource:
but
case DataSource:
Generics doesn’t work on TableViewDeleate, TableViewDataSource because of a bug
ds.respondsToSelector(“tableView:numberOfRo wsInSection:”) is false http://www.openradar.me/radar? id=5829206453780480
case API Call:
Request<T>
Request<[User]>
Object Mapper
AnyObject -> T var orm = { (json: AnyObject) ->
User in … … return user } var orm = { (json: AnyObject) -> Media in … … return media }
Completion Handler
T -> () var handler = { ( item:User) ->
() in … … } var handler = { (item:Media) -> () in … … }
fast useful flexible practical
I like generics :)
thanks
bit.ly/tinyjson bit.ly/code20150416
question?