Advanced Swift
A deep dive into Swift’s features, from low-level programming to high-level abstractions.
by Chris Eidhof, Ole Begemann, Florian Kugler, and Ben Cohen
The videos accompanying Advanced Swift build on top of the material explained in the book. Through live coding, we show how to apply the different topics in real code. Here is the full table of contents for the videos:
C Interoperability 1h12min
In this video we create a wrapper around Cairo, a C library for drawing with vector graphics.
- 
											Introduction 0:00We create a new Swift Package and import the Cairo C library. 
- 
											Wrapping Cairo Types in Classes 13:17We create Swift classes to help with type-safety and memory management. 
- 
											Protocols vs. Subclassing 31:52We explore the trade-offs between modeling Cairo's type hierarchy using protocols vs. subclassing. 
- 
											Working with <code>Unmanaged</code> 48:04We wrap a streaming SVG API and perform manual memory management using Unmanaged.
- 
											Testing on Linux using Docker 1:02:37We show how to test the Swift Cairo wrapper on Linux by running it inside a container. 
String Parsing 1h
We extend the CSV parsing example from the book to support more features and improve its performance.
- 
											Introduction 0:00We build the parser from the book and discuss its trade-offs. 
- 
											Encoding Parsing State in Functions 18:13We show how modeling state using different functions makes the parser more maintainable. 
- 
											Parsing Performance 39:52We measure and improve the performance of our parser by working on different string views. 
Collection Protocols 58min
We show how to work with Swift's built-in Collection protocols by creating a custom SortedArray collection.
									
- 
											Introduction 0:00We create a naive implementation of a sorted array. 
- 
											Improving SortedArray using Binary Search 07:03We implement binary search on SortedArrayto make lookups and insertions much faster.
- 
											Conforming to Collection Protocols 17:37We conform to Collection,BidirectionalCollectionandRandomAccessCollection, and discuss why we can't conform toMutableCollectionandRangeReplaceableCollection.
- 
											Protocol Constraints and Conditional Conformance 40:57We work with protocol constraints to add conditional functionality, and show how to use conditional conformance. 
- 
											Adding a SortedCollection Protocol 42:55We create a custom SortedCollectionprotocol on top ofCollectionand move most of the functionality from ourSortedArrayinto the new protocol.
- 
											Conforming SortedSet to SortedCollection 50:07We create a new type, SortedSet, and conform it to our new protocol. With little effort we get a lot functionality.
Functions 36min
We build a validation library using higher-order functions.
- 
											Introduction 0:00We define our Validatortype and show how to use it.
- 
											Generic Validation Helpers 7:34We implement helper methods to create basic validators for checking a single property. 
- 
											Combining Validators 16:29We create a function to combine multiple validators into a single validator. 
- 
											Lifting Validators 22:18We show how to lift validators from one type to a containing type by using key paths. 
- 
											Transforming The Error Message 27:25We add a helper function that allows us to override the error message for a specific validator. 
- 
											Throwing Validation Errors 31:39We show how to convert a validator into a function that throws whenever a validation error happens. 
Encoding & Decoding Graphs 46min
We show different representations of graphs and how they work with Codable.
									
- 
											Introduction 0:00We build a class-based graph data structure and show why it can't be serialized using Codable.
- 
											Defining the Graph Struct 9:51We implement the graph as a struct without reference types. 
- 
											Inserting into the Graph 13:15We show how to build graphs using the struct-based API. 
- 
											Transforming Node to Graph 20:41We implement a function that automatically transforms a class-based graph into a struct-based graph. 
- 
											Transforming Graph to Node 31:41We also implement the reverse transformation, from a struct-based graph back to a class-based graph. 
- 
											Improving the Graph API Using an Opaque Type 42:59We hide implementation details by creating an opaque wrapper type for our object identifiers.