Group Group Group Group Group Group Group Group Group

Factory chapter: code refactoring suggestion

#1

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
#2

@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