title: What is the flow for updating complication data for Apple Watch?
body: <p>I've been following a lot of tutorials on the internet to learn how to set up the complication. I have no problem getting the complication set up as expected. </p>
  
  <p>Until the initial timeline entries expire. After 12 hours, I do not know how to update it to keep the complication live. I'll share everything I have below and hopefully somebody can help fill me in.</p>
  
  <p>Here, I create the variables for my data that I want to display on the complication.</p>
  
  <pre><code>struct data = {
  var name: String
  var startString: String
  var startDate: NSDate
  }
  </code></pre>
  
  <p>The following array is a container for this data.</p>
  
  <pre><code>var dataArray = [data]
  </code></pre>
  
  <p>This allows the complication to be shown when the watch is locked.</p>
  
  <pre><code>func getPrivacyBehaviorForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationPrivacyBehavior) -&gt; Void) {
      handler(.ShowOnLockScreen)
  }
  </code></pre>
  
  <p>This allows forward Time Travel on the complication.</p>
  
  <pre><code>func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -&gt; Void) {
      handler([.Forward])
  }
  </code></pre>
  
  <p>Here, I set the starting time of the timeline to be equal to now.</p>
  
  <pre><code>func getTimelineStartDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -&gt; Void) {
      handler(NSDate())
  }
  </code></pre>
  
  <p>Here, I set the ending time of the timeline to be equal to 12 hours from now.</p>
  
  <pre><code>func getTimelineEndDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -&gt; Void) {
      handler(NSDate(timeIntervalSinceNow: (60 * 60 * 12)))
  }
  </code></pre>
  
  <p>Here, I create the template of the complication. This is to show sample data for users when they see my complication while browsing all complications on their watch.    </p>
  
  <pre><code>func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -&gt; Void) {
  
      let headerTextProvider = CLKSimpleTextProvider(text: "Some Data")
      let body1TextProvider = CLKSimpleTextProvider(text: "Some Data Time")
      let template = CLKComplicationTemplateModularLargeStandardBody()
      template.headerTextProvider = headerTextProvider
      template.body1TextProvider = body1TextProvider
  
      handler(template)
  }
  </code></pre>
  
  <p>This creates the very first timeline entry for the complication. As soon as the complication is enabled, this code will be run and immediately populate the complication accordingly.</p>
  
  <pre><code>func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -&gt; Void) {
  
      createData()
  
      if complication.family == .ModularLarge {
  
          if dataArray.count != 0 {
  
              let firstData = dataArray[0]
              let headerTextProvider = CLKSimpleTextProvider(text: firstData.name)
              let body1TextProvider = CLKSimpleTextProvider(text: firstData.startString)
              let template = CLKComplicationTemplateModularLargeStandardBody()
              template.headerTextProvider = headerTextProvider
              template.body1TextProvider = body1TextProvider
              let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: template)
              handler(timelineEntry)
          } else {
              let headerTextProvider = CLKSimpleTextProvider(text: "No Data")
              let body1TextProvider = CLKSimpleTextProvider(text: "Create some data")
              let template = CLKComplicationTemplateModularLargeStandardBody()
              template.headerTextProvider = headerTextProvider
              template.body1TextProvider = body1TextProvider
  
              let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: template)
              handler(timelineEntry)
          }
  
      } else {
          handler(nil)
      }
  
  }
  </code></pre>
  
  <p>This is where I create timeline entries for all of the data that I currently have. </p>
  
  <pre><code>func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: ([CLKComplicationTimelineEntry]?) -&gt; Void) {
  
      createData()
  
      var entries = [CLKComplicationTimelineEntry]()
  
      for dataObject in dataArray {
  
          if entries.count &lt; limit &amp;&amp; data.startDate.timeIntervalSinceDate(date) &gt; 0 {
  
              let headerTextProvider = CLKSimpleTextProvider(text: dataObject.name)
              let body1TextProvider = CLKSimpleTextProvider(text: dataObject.startString)
              let template = CLKComplicationTemplateModularLargeStandardBody()
              template.headerTextProvider = headerTextProvider
              template.body1TextProvider = body1TextProvider
              let timelineEntry = CLKComplicationTimelineEntry(date: NSDate(timeInterval: (-10*60), sinceDate: data.startDate), complicationTemplate: template)
              entries.append(timelineEntry)
  
          }
  
      }
  
      handler(entries)
  
  }
  </code></pre>
  
  <p>This tells the watch when to update the complication data.</p>
  
  <pre><code>func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -&gt; Void) {
      handler(NSDate(timeIntervalSinceNow: 60 * 60 * 6))
  }
  </code></pre>
  
  <p><strong>This is where I'm running into problems.</strong> </p>
  
  <p>How do I create my new data and reload the timeline? What is the flow? I'm not trying to extend the timeline, but rather to completely replace it. I'm at a complete loss. <a href="https://developer.apple.com/library/watchos/documentation/General/Conceptual/AppleWatch2TransitionGuide/CreatingaComplication.html">Apple's docs</a> are pretty vague when it comes to this point. I know that I need to implement the following methods, but I don't know how. Can somebody help me to fill in this code?</p>
  
  <pre><code>func requestedUpdateDidBegin() {
      createData() //I assume createData() goes here? If so, how do I populate the new timeline entries based on the results?
  }
  
  func requestedUpdateBudgetExhausted() {
      //This can't possibly be the case as I haven't gotten it to work once.
  }
  
  func reloadTimelineForComplication(complication: CLKComplication!) {
        //This method appears to do nothing.
  }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Thanks to El Tea, I've got it working. I need to add an instance of CLKComplicationServer to requestedUpdateDidBegin and put the reloadTimeline method inside. </p>
  
  <p>Here is the updated code:</p>
  
  <pre><code>func requestedUpdateDidBegin() {
      print("Complication update is starting")
  
      createData()
  
      let server=CLKComplicationServer.sharedInstance()
  
      for comp in (server.activeComplications) {
          server.reloadTimelineForComplication(comp)
          print("Timeline has been reloaded!")
      }
  
  }
  
  func requestedUpdateBudgetExhausted() {
      print("Budget exhausted")
  }
  </code></pre>