The Book

Metal by Example was published as an e-book on Gumroad in October 2015. As of September 2016, you can name your own price. As of March 2023, after selling almost four thousand copies, I made the decision to remove Metal by Example from sale. You can download the PDF here for free. More than seven years after publication, it is quite out-of-date, but I will keep it here indefinitely for posterity.

Sample Code

The sample code for the book is available as MIT-licensed open source and is hosted on Github.

View the repository here

33 thoughts on “The Book”

    1. When I know, you’ll know. The price of the book will be competitive with other technical books on the market, with the e-book selling for a little less than the paperback.

    1. We’re targeting mid-July for the e-book release, with the softcover to follow later. The July timeframe is entirely contingent on several factors: editing, e-book and softcover production, and how significant the changes announced at WWDC 2015 are.

  1. Cant wait to by the book
    Will any of the code be in swift ?
    I can convert it to for myself but then i might make it less efficiëntly working Since im not 100% familier with the metal api

    1. The sample code for the book is in Obj-C, but the most recent article on Metal Performance Shaders has sample code in Swift. Fortunately, the concepts transfer pretty readily between the two.

  2. Hiya,

    Checking in again since May! Great to hear your book is almost ready! Like Kristof, I really would prefer that book in Swift. I know I’m only speaking for myself, but whether or not your book is in Swift is a crucial point for me.

    (hoping you’ll convert to Swift)

    Regards,
    Kelvin

    1. I respect that a lot of devs are using Swift now, and if I had it all to do again, I’d do the whole project in Swift. This release will be in Obj-C. Having said that, the sample code will be available under a pretty liberal license, so if someone wants to port it to Swift, I’d be open to that collaboration.

  3. Thanks a lot, I can’t wait to read your book.

    For me it is great it is an Objective-C book.

    (I always code in Objective-C++ for the Apple platform for better cross-platform portability (and since I am a C++ nerd), so I can reuse BIG chunks of code on other platforms as well, and so Objective-C is great for me)

  4. Hi there!

    SUPER excited to see this book published!

    Just curious if there were any updates on the publication of the book? 🙂

    Thanks!

  5. I would love to see some expansion of the compute kernel section. Specifically I’m interested in operating on large arrays of complex data in parallel. Getting structs into metal without copying is somewhat of a challenge.

  6. I try to run de examples, and I got these kind of errors? any idea?

    Unknown type name ‘CAMetalLayer’; did you mean ‘CATextLayer’?
    Unknown receiver ‘CAMetalLayer’; did you mean ‘CATextLayer’?
    No type or protocol named ‘CAMetalDrawable’

    1. Normally this error indicates you’re trying to run a Metal project in the iOS Simulator. Metal isn’t supported in the Simulator, so you’ll need to build with Generic Device or a physical device scheme selected.

  7. Apple will remove OpenGL from iOS and macOS, which have scared me, my app will stop working later.
    I hope that I can learn Metal quickly by reading your book, and rewrite them with Metal.
    Thanks!

  8. Hi! Do you have any tutorials or books on texturing 16-bit packed pixel formats? For example 5_5_5_1, 4_4_4_4 or 5_6_5.

      1. Very exciting to hear! Is there a timeline for the next book? Just bought the first one, I should probably finish that first…

        1. Unfortunately, the new book project is shelved indefinitely. But I have recently revisited all of the book sample code (available on Github), and it’s fully updated for iOS 13, including the iOS Simulator.

          1. Just wanted to thank you for the insightful blog posts and the original book. I hope that an opportunity arises where the new book project can be resumed since I find your explanations easier to understand than most. Thanks for helping people get a grasp on Metal and graphics programming.

  9. Karthikeyan Alagarswamy

    What’s the difference between using Metal with Swift vs Objective C? Any performance differences?

    1. I have heard anecdotally that Debug builds of Swift apps are substantially slower than Release builds, but I think the practical overhead of Swift relative to Objective-C in production is quite small (<5%). Most developers would be hesitant to do new development in Objective-C, so if you’re already using Swift, I think it’s a fine choice. Conversely, if you’re partial to Objective-C, you have more options when it comes to optimizing after eliminating all the obvious bottlenecks (disabling ARC, for instance, or rewriting performance-critical layers in C++).

      1. Karthikeyan Alagarswamy

        Thank you. I’m new to iOS development. I have been learning both Objective C and Swift for quite sometime. But, didn’t know which one to pick for Metal development based on execution performance . So, my understanding here is, ObjC gives better options when it comes tweak the underlying layers? Is this a fair understanding?

        1. I believe so, but that’s heavily colored by my own experience and preferences. And you have to weigh the fact that developing in Swift often takes less code and is actively encouraged and supported by Apple.

Leave a Reply to Radu Iulian Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.