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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nate Cook
March 31, 2016
Programming
74
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
640
Flexible Code for Generic Collections
natecook1000
7
1.3k
SwiftDoc.org Preview
natecook1000
0
320
Other Decks in Programming
See All in Programming
はじめてのPLATEAU
nokonoko1203
1
440
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
100
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
200
Kotlinの15年とServer-Side Kotlin
n_takehata
1
200
Event is what happens
moro
2
3.5k
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
300
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
770
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.7k
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
1.5k
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
130
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
3
1.4k
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
280
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.4k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
Fireside Chat
paigeccino
43
4.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Optimising Largest Contentful Paint
csswizardry
37
4k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
570
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
890
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
590
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Test your architecture with Archunit
thirion
2
2.5k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
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