SlideShare a Scribd company logo
Generics in
Theory and Practice
@MicheleTitolo
What We’ll Cover
What Is Generic
Programming
Super Reusable
Type Independent
The Generics Manifesto
Not A Promise
Parts Implemented In
Swift 3
Generics In The
Standard Library
Collections
Can Hold Anything
Force Type Decisions
Global Functions
Widely Applicable
Transformations
Single Type Constraint If Any
Language Limitations
Variables That Are Classes + Protocols
Protocols With Associated Types
The stdlib Is Protocol Oriented
public init<Subject, C : Collection where C.Iterator.Element == Child, C.SubSequence : Collection,
C.SubSequence.Iterator.Element == Child, C.SubSequence.Index == C.Index, C.SubSequence.Indices :
Collection, C.SubSequence.Indices.Iterator.Element == C.Index, C.SubSequence.Indices.Index ==
C.Index, C.SubSequence.Indices.SubSequence == C.SubSequence.Indices, C.SubSequence.SubSequence ==
C.SubSequence, C.Indices : Collection, C.Indices.Iterator.Element == C.Index, C.Indices.Index ==
C.Index, C.Indices.SubSequence == C.Indices>(_ subject: Subject, children: C, displayStyle:
Mirror.DisplayStyle? = default, ancestorRepresentation: Mirror.AncestorRepresentation = default)
One-Offs
Swift Generics in Theory and Practice
Except When Working Around
Language Limitations
Being Cool
Swift Generics in Theory and Practice
What
Can
We
Learn?
Generics Have Purpose
Design Decision Or
Last Resort
Create True Reusability
Does Type Matter?
If It Matters,
Probably Not Generic
Surface And Enforce
Type Decisions
Using Generics Are Making
Type Decisions
Generics Enforce That Choice
Any Is Poor Form
Coming Soon
Recursive Protocol
Constraints
Associatedtypes Reference
Enclosing Type
Sequence
And Leaky Abstractions
Nested Generics
Compiler Feature
Generics Can Contain Generics
Enhanced
Existentials
Generic Types Are Enforced
At Compile Time
Existential Types Are
Enforced At Runtime
id<UITableViewDataSource,
UITableViewDelegate>
UITableViewDataSource &
UITableViewDelegate
Only Works With Concrete Protocols
In Swift 3
Workaround With Generics
Goal To Be Fixed In Swift 4
Swift Is Evolving!
Get
Involved
Photo Credits
•https://unsplash.com/search/birds?photo=XzW66yAyVBA

•https://unsplash.com/search/birds?photo=GL6ORxDMswI

•https://unsplash.com/search/birds?photo=kuJkUTxR0z4

•https://unsplash.com/search/birds?photo=ea4OvouLpZk

•https://unsplash.com/search/birds?photo=W341a11Rt1g

•https://unsplash.com/search/birds?photo=eRxKUD3S7M8

•https://unsplash.com/search/birds?photo=WooFf3yav6U

•https://unsplash.com/search/birds?photo=yhnOTbw9SPY

•https://www.flickr.com/photos/
88776252@N00/5332505572/

More Related Content

PDF
Kotlin generics
PPTX
PDF
Explicit Semantic Analysis
PPT
Datatypes in C Language
PPTX
C programinng
PDF
Python Tutorial Questions part-1
PDF
The low level awesomeness of Go
PDF
deep devops - learning to learn dotScale 2017
Kotlin generics
Explicit Semantic Analysis
Datatypes in C Language
C programinng
Python Tutorial Questions part-1
The low level awesomeness of Go
deep devops - learning to learn dotScale 2017

Similar to Swift Generics in Theory and Practice (20)

PPTX
1. Mini seminar intro
PDF
Mining and Untangling Change Genealogies (PhD Defense Talk)
PDF
🐍⚡ “Python Panache: Code Like a Pro, Not a Programmer!”
PDF
117 A Outline 25
PDF
Generics Tutorial
PPTX
Code Metrics
DOCX
Intervies
PDF
Library management system
PDF
Generics Tutorial
PPTX
Introduction to C++ Programming
DOC
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
PDF
cprogramming questions for practice end term
PPTX
lecture13-DTrees-textcat.pptxnnnnnnnnnnnnnnnnnnnnnn
PDF
Oos Short Q N
PPTX
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
PDF
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
PPT
Future Programming Language
1. Mini seminar intro
Mining and Untangling Change Genealogies (PhD Defense Talk)
🐍⚡ “Python Panache: Code Like a Pro, Not a Programmer!”
117 A Outline 25
Generics Tutorial
Code Metrics
Intervies
Library management system
Generics Tutorial
Introduction to C++ Programming
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
cprogramming questions for practice end term
lecture13-DTrees-textcat.pptxnnnnnnnnnnnnnnnnnnnnnn
Oos Short Q N
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
Future Programming Language
Ad

More from Michele Titolo (20)

PDF
Writing Design Docs for Wide Audiences
PDF
Beam Me Up: Voyaging into Big Data
PDF
APIs: The Good, The Bad, The Ugly
PDF
Tackling the Big, Impossible Project
PDF
No Microservice is an Island
PDF
From iOS to Distributed Systems
PDF
More than po: Debugging in LLDB
PDF
APIs for the Mobile World
PDF
Protocols promised-land-2
PDF
Multitasking
PDF
Making friendly-microservices
PDF
More Than po: Debugging in LLDB @ CocoaConf SJ 2015
PDF
The Worst Code
PDF
More than `po`: Debugging in lldb
PDF
Can't Handle My Scale v2
PDF
Can't Handle My Scale
PDF
Cocoa Design Patterns in Swift
PDF
Mastering the Project File (AltConf)
PDF
APIs: The Ugly
PDF
That's Not My Code!
Writing Design Docs for Wide Audiences
Beam Me Up: Voyaging into Big Data
APIs: The Good, The Bad, The Ugly
Tackling the Big, Impossible Project
No Microservice is an Island
From iOS to Distributed Systems
More than po: Debugging in LLDB
APIs for the Mobile World
Protocols promised-land-2
Multitasking
Making friendly-microservices
More Than po: Debugging in LLDB @ CocoaConf SJ 2015
The Worst Code
More than `po`: Debugging in lldb
Can't Handle My Scale v2
Can't Handle My Scale
Cocoa Design Patterns in Swift
Mastering the Project File (AltConf)
APIs: The Ugly
That's Not My Code!
Ad

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
L1 - Introduction to python Backend.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Digital Strategies for Manufacturing Companies
PDF
Nekopoi APK 2025 free lastest update
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Wondershare Filmora 15 Crack With Activation Key [2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
Softaken Excel to vCard Converter Software.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
CHAPTER 2 - PM Management and IT Context
Adobe Illustrator 28.6 Crack My Vision of Vector Design
VVF-Customer-Presentation2025-Ver1.9.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
L1 - Introduction to python Backend.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Introduction to Artificial Intelligence
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Understanding Forklifts - TECH EHS Solution
Digital Strategies for Manufacturing Companies
Nekopoi APK 2025 free lastest update
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Swift Generics in Theory and Practice