title: Chain of delegates in Swift
body: <p><strong>TDLR;</strong> I have three classes, when <code>Class A</code> object is updated, it's calling on its delegate (<code>Class B</code>) which is calling on its delegate (<code>Class C</code>) without doing anything else. <code>Class C</code> will use <code>Class B</code> in different ways depending on the values in <code>Class A</code>. <code>Class B</code> need to know of its <code>Class A</code> at touch events. Is this acceptable?</p>
  
  <pre><code>classA { var information: String }
  classB { var thing: ClassA thing.delegate = self }
  classC { var things: [ClassB] for thing in things { thing.delegate = self } } 
  </code></pre>
  
  <p><strong>My real example</strong></p>
  
  <p>I have three classes: A <code>mapViewController</code>, a <code>mapMarker</code> and a <code>place</code> (model). The map holds multiple <code>mapMarker</code>s, and every <code>mapMarker</code> has a property <code>place</code>, which contains information of what the marker should look like (like place type, "bar", "restaurant" etc). The place might receive new information via a silent push notification, and hence being updated. When the place is updated, I need to notify the <code>mapViewController</code> that the marker needs to be redrawn (I'm using MapBox and their annotations doesn't support redrawing in any way but removing and adding the marker again, since the <code>imageForAnnotation</code> method is a delegate one.)</p>
  
  <p>My first thought was to make two protocols <code>placeDelegate</code> and <code>mapMarkerDelegate</code>.</p>
  
  <p>Place:</p>
  
  <pre><code>protocol PlaceDelegate: class
  {
    func placeUpdated()
  }
  
  class Place {
      weak var delegate: PlaceDelegate?
  
      var propertyThatCanBeUpdate: String {
          didSet { 
          //Checking if the newValue == oldValue 
          delegate.placeUpdated()
          }
  }
  </code></pre>
  
  <p>MapMarker</p>
  
  <pre><code>protocol MapMarkerDelegate: class
  {
      markerShouldReDraw(mapMarker: MapMarker)
  }
  
  class MapMarker: PlaceDelegate {
      var place: Place!
      weak var delegate: MapMarkerDelegate?
      init(place: Place) {
          self.place = place
          place.delegate = place
      }
  
      func placeUpdate()
      {
          delegate.markerShouldReDraw(self)
      }
  
  } 
  </code></pre>
  
  <p>MapViewController</p>
  
  <pre><code>class MapViewController {
  //I could easily set the marker.delegate = self when adding the markers
  
  func markerShouldReDraw(mapMarker: MapMarker)
      functionForRedrawingMarker()
  }
  </code></pre>
  
  <p>This feels a bit ugly, and a bit weird that the MapMarker is just passing the "my place has been updated" information forward. Is this acceptable as far as performance goes? Should I use some kind of <code>NSNotification</code> instead? Should I make the <code>MapViewController</code> the delegate of <code>place</code> and search my array of <code>mapMarker</code> for the one holding the correct <code>place</code>? </p>