Chapter 13 (Iterator) - Tutorial example doesn't use Iterator pattern

In chapter 13 to demonstrate iterator pattern in action, author added Filter conformance to Sequence protocol.
However at the moment of its usage in method addAnnotations(), for in loop launched over array filter.businesses, not over filter (whose type supports iteration).

Now:

    for business in filter.businesses {
      guard let viewModel = annotationFactory.createBusinessMapViewModel(for: business) else {
        continue
      }

Expected:

    for business in filter {
      guard let viewModel = annotationFactory.createBusinessMapViewModel(for: business) else {
        continue
      }

Wow this is a great catch! Thanks, I can’t believe that slipped through. I will update this in the next edition.

1 Like

I looked into this and it turned out that the instructions in the book did use filter, but somehow the final example project still used filter.businesses. It has been updated and this fix will be included in the Swift 5 version of the book!

Cool, thanks for fixing that