Reviewed the "Modern Auto Layout" book

Discussion in 'iOS Programming' started by bartvk, Jan 1, 2019.

Tags:
  1. bartvk macrumors 6502

    bartvk

    Joined:
    Dec 29, 2016
    Location:
    The Netherlands
    #1
    Hi everyone, two months ago I reviewed the new "Modern Auto Layout" book and here's my review of it. I've also posted it on reddit so you might've seen it.

    If you don't feel like reading, then my conclusion basically is: I give it my full recommendation and I think it's great for beginners and intermediates in Auto Layout. I have some minor criticisms, to which the author (Keith Harrison) replied. Scroll to bottom of post for his reply and a discount.

    Anyway, I was quite interested in the book because I still meet developers that haven't learned it. But when talking to people, I couldn’t point them to good documentation, because although Erica Sadun wrote a book on the subject, she never updated it, not even for Swift.

    Back then I really needed that book, because I found the learning curve for Auto Layout steep, and it brought some frustration with it. Although I've largely mastered the topic, decent documentation is welcomed. Since iOS 12 didn't bring big changes to Auto Layout (mainly performance improvements), I expect the contents to age gracefully.

    The title of the book is explained to mean that modern Auto Layout means:

    * Layout Anchors and layout guides and stackviews
    * Using Dynamic Type
    * Safe area layout guides, and using auto layout in scroll views

    Difficulty level

    This book is meant for beginners to intermediate level. For beginners, there's chapters about using Interface Builder, about creating constraints in code and about stack views.

    For intermediate levels, there's layout priorities, a chapter about understanding the layout engine, and about adapting for size (particularly supporting iPad multitasking).

    I've been doing iOS development for a number of years now. I feel I've mastered Auto Layout but still found a few gems:

    • Useful tips for debugging layout problems;
    • A dive into what happens when UIStackView doesn't do what you want;
    • The chapter "Understanding The Layout Engine"; I had a vague understanding of the various steps but this chapter goes into each nitty-gritty step.

    Title and style

    The title is accurate, which is IMHO refreshing. It really is MODERN Auto Layout; it told me about some old habits I picked up since iOS 6 but which are no longer necessary, such as adding constraints in a custom view's updateConstraints(). Also, it takes a look at the various ways of creating constraints, and dismissing some of them, like VFL.

    Some general observations:

    • If you're the type of person that wants to be challenged: at the end of most chapters, there's a couple of programming exercises along with some hints
    • It's very readable, and doesn't use stilted language. Just check out the blog if you want to get a taste about Keith's writing style. It's at https://useyourloaf.com/

    What could be better?

    I don't feel that major aspects are missing from the book, however a minor detail that could've been discussed, is the (lack of) Auto Layout support for headers and footers of UITableView (not section headers, but the table header). I've not been able to put views in the UITableView.tableViewHeader and .tableViewFooter properties and have the constraints behave correctly without tricks. Perhaps this kind of stuff is better discussed in a blog entry, but then the book could've included a warning about this.

    Another observation is that no frameworks are discussed. Personally, I prefer not to have extra code between me and my constraints, but SnapKit has 14k stars on Github. So obviously, there is a demand for a different API.

    Conclusion: this is currently the one and only book on Auto Layout and it's a very complete one at that. Suitable for any iOS developer up to intermediate.

    The author Keith Harrison has replied to my criticisms as follows:

    "The point about table view headers and footers is a good one. That is the sort of Auto Layout pain that I wanted to include in the book. It didn’t make it into the first edition but I’ll certainly look at including something in a future (free) update. Inevitably there are a number of topics that did not make the cut. I had originally planned on having at least an appendix that compared the different third-party frameworks like SnapKit but I just ran out of time."

    I asked for a discount code to include in my review and he happily provided it:
    https://gum.co/albook/2019

    Link will give 20% off and is valid until Friday midnight, UTC time.
     
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Autolayout is probably the biggest pain point for iOS development. Table headers and table section headers are a particular problem. I do make them work but IB's support for them is meager.
     
  3. bartvk thread starter macrumors 6502

    bartvk

    Joined:
    Dec 29, 2016
    Location:
    The Netherlands
    #3
    True. It took some time before I realized that you're basically stating a bunch of rules. And then a lot more time before it became intuitive how to make the layout unambiguous.

    Google "f@#$ auto layout" for some fun :)
     

Share This Page