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
Collections in Swift
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nate Cook
March 31, 2016
Programming
70
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
610
Flexible Code for Generic Collections
natecook1000
7
1.3k
SwiftDoc.org Preview
natecook1000
0
300
Other Decks in Programming
See All in Programming
数百円から始めるRuby電子工作
tarosay
0
140
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
340
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.5k
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
140
Cloudflare is Agents
chimame
0
150
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
160
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
770
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
Featured
See All Featured
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
119
120k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
520
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Un-Boring Meetings
codingconduct
0
380
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
Designing Experiences People Love
moore
143
24k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
BBQ
matthewcrist
89
10k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Statistics for Hackers
jakevdp
799
230k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
790
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