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
Collections in Swift
Search
Nate Cook
March 31, 2016
Programming
71
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Collections in Swift
Talk at CocoaConf Chicago, March 2016
Nate Cook
March 31, 2016
More Decks by Nate Cook
See All by Nate Cook
Swift's Pointy Bits
natecook1000
0
620
Flexible Code for Generic Collections
natecook1000
7
1.3k
SwiftDoc.org Preview
natecook1000
0
300
Other Decks in Programming
See All in Programming
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
Family mrubyの進捗
kishima
1
110
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
150
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
130
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
430
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
150
Deep dive into the select statement (GopherCon UK)
jespino
0
170
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
Security issues being discussed on Web Platforms
petamoriken
0
670
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
170
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
690
We Are The Robots
honzajavorek
0
360
Designing for Performance
lara
611
70k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
From π to Pie charts
rasagy
0
360
Ethics towards AI in product and experience design
skipperchong
2
370
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
310
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
520
BBQ
matthewcrist
89
10k
Transcript
Collections in Swift
Nate’s favorite part of Swift: The Standard Library Collections System
Protocol-oriented programming
Protocols in Objective-C
Protocols in Swift
Protocols of Swift collections
This session 1. The “Problem” 2. How Swift's collections work
3. New approaches
None
! " #
None
None
! " #
None
None
None
This session 1. The “Problem” 2. How Swift's collections work
3. New approaches
None
None
A sequence is a series of values we can access
one at a time » 6'2", 5'7", 5'9", 5'4", 5'11" » 0xEF 0xBB 0xBF 0x4E 0x61 0x74 0x65 » 22, 27, 4, 8, 28, 14, ... » 0, 1, 2, 3, 4, 5, 6, 7, ...
Sequences
SequenceType GeneratorType
SequenceType requirements func generate() -> Generator GeneratorType requirements func next()
-> Element?
One element at a time
let numbers = [1, 2, 3, 4] for num in
numbers { print(num) } ...is equivalent to: var gen = numbers.generate() while let num = gen.next() { print(num) }
Iteration » contains(_:) » minimumElement() / maximumElement() » map(_:) /
filter(_:) / reduce(_:combine:) » prefix(_:) / dropFirst(_:)
demo
None
None
Collections provide indexed subscript access to their elements » Arrays
» String views (i.e., "Hi there".characters) » Sets » Dictionaries
CollectionType
CollectionType requirements var startIndex: Index var endIndex: Index subscript(i: Index)
-> Generator.Element
Quick diversion: Index types » Forward index types » Bidirectional
index types » Random-access index types
CollectionType requirements var startIndex: Index var endIndex: Index subscript(i: Index)
-> Generator.Element
Indexed access to elements » Collections are sequences, too »
prefixUpTo(_:), prefixThrough(_:), suffixFrom(_:) » subscript(Range<Index>) » count, isEmpty » indices
Sequenception
demo
None
None
Range-replaceable collections support arbitrary subrange replacement » Pretty much just
arrays
RangeReplaceableCollectionType requirements init() func replaceRange<C: CollectionType where C.Generator.Element == Generator.Element>
(subRange: Range<Index>, with newElements: C)
Mix-and-match » append(_:), appendContentsOf(_:) » insert(_:), insertContentsOf(_:) » removeAtIndex(_:), removeRange(_:)
» removeAll()
demo
None
None
This session 1. The “Problem” 2. How Swift's collections work
3. New approaches
demo
SwiftDoc.org
None
Thank you! Nate Cook @nnnnnnnn