Factory chapter: code refactoring suggestion

Quick suggestion while reading the book, I am a big fan of Swift compactMap function and on page 178 (the factory chapter) you could have refactor the addAnnotations method as follow:

  private func addAnnotations() {
    let annotations = businesses.compactMap({annotationFactory.createBusinessMapViewModel(for: $0)})
    
    mapView.addAnnotations(annotations)
  }

thanks

Alex

1 Like

@giguerea Thanks very much for your suggestion! The nature of programming is such that, there is definitely more than one way to skin a cat! The question arises, is the approach youโ€™re using accomplishing your goal, using minimal code, that is understandable, and easy to read? If the answer is โ€œyesโ€ then more power to you! :slight_smile:

2 Likes