A new Swift book is out: Optimzing Collections by Károly Lőrentey. I had a small part in this as the book’s technical reviewer, and I highly recommend it.
Károly first released the book as a beta version a few months ago and now the final version has been published through objc.io.
You’ll learn:
- How to write a custom collection type that conforms to Swift’s
Collection
protocols. - How to implement value semantics with copy-on-write behavior in your own types.
- How to measure the performance of your custom collection and make it a lot faster than the built-in collection types (for certain tasks; different data structures make different tradeoffs).
This isn’t a book that just scratches the surface. Károly really goes into detail, especially on that last point. I love how practially every chapter ends with a set of charts illustrating the performance characteristics of the code written in that chapter — and those results in turn form the basis for subsequent optimizations in the next chapter.
If you want to get a feel for the book, watch Károly’s talk at dotSwift 2017. If you like the talk and would like to learn more, I guarantee you’ll love the book.
Lastly, I think the book is a very nice companion to Advanced Swift. Collections also play a big role in Advanced Swift, but with a different focus: we explore the collection protocols in more detail, but we don’t discuss the performance aspects at the level of Optimizing Collections.