title: How to display Current Time (Realtime) in iOS 14 Home Widget
body: <p>I am developing an application for ios 14 Home Widget and I am facing a problem while showing the current time (digital clock) that the widget not getting updated every sec. As we all know, Apple does not allow to trigger timeline every second is there any other way to display the current time with the realtime updates?</p>
  <p>I tried these methods but not works as expected</p>
  <pre><code>class NetworkManager: ObservableObject {
      @Published var dateIs = Date()
      
      init() {
          startTimer() // fetch data must be called at least once
      }
      private  func startTimer() { 
          let t = RepeatingTimer(timeInterval: 3)
                  t.eventHandler = {
                      DispatchQueue.main.async() {
                          // your UI update code
                          print(&quot;Timer Fired&quot;)
                       self.dateIs = Date()
                          WidgetCenter.shared.reloadAllTimelines() // reload timelines
                      }
                      if(false){   //I know this makes no sense, but it works. Go figure...
                          t.suspend()
                      }
                  }
                  t.resume()
  
      }
  }
  
  
  struct Provider: TimelineProvider {
  
      init() {
          networkManager = NetworkManager()
      }
  
      
      @AppStorage(&quot;storedData&quot;, store: UserDefaults(suiteName: &quot;group.com.name&quot;))
      var data: Data  = Data()
      
      func placeholder(in context: Context) -&gt; WidgetEntry {
          let entry = WidgetEntry(date: Date(), storedData: storedData[0], dateIs: networkManager.dateIs)
          return entry
      }
      
      func getSnapshot(in context: Context, completion: @escaping (WidgetEntry) -&gt; Void) {
          
          guard let storedData: WidgetTemplate = try? JSONDecoder().decode(WidgetTemplate.self, from: data) else { return }
          let entry = WidgetEntry(date: Date(), storedData: storedData, dateIs: networkManager.dateIs)
            
          completion(entry)
      }
      
      func getTimeline(in context: Context, completion: @escaping (Timeline&lt;WidgetEntry&gt;) -&gt; Void) {
      
          guard let storedData: WidgetTemplate = try? JSONDecoder().decode(WidgetTemplate.self, from: data) else { return }
          let entry = WidgetEntry(date: Date(), storedData: storedData, dateIs: networkManager.dateIs)
          
          let currentDate = Date()
          let refreshDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)!
          
          let timeline = Timeline(entries: [entry], policy:  .after(refreshDate))
          completion(timeline)
      }
      
  }
  </code></pre>