title: How to refresh Widget data?
body: <p>My Code fetches two <code>JSON</code> variables and should show them on my Widget.
  The Widget stays blank. Without widget it shows me everything correct in my application.</p>
  <p>What am I doing wrong? The API in the code is only for testing so you can also check that.
  Is there something I need to change to make it show in the widget?</p>
  <p>My Struct:</p>
  <pre><code>import Foundation
  
  struct Results: Decodable {
      let data: [Post]
  }
  
  struct Post: Decodable, Identifiable {
      let id: String
      var objectID: String {
          return id
      }
      let home_name: String
      let away_name: String
  }
  </code></pre>
  <p>Fetching JSON:</p>
  <pre><code>import Foundation
  
  class NetworkManager: ObservableObject {
      
      @Published var posts = [Post]()
      
      @Published var test = &quot;&quot;
      @Published var test2 = &quot;&quot;
      
      func fetchData() {
          if let url = URL(string: &quot;https://livescore-api.com/api-client/teams/matches.json?number=10&amp;team_id=19&amp;key=I2zBIRH3S01Kf0At&amp;secret=6kLvfRivnqeNKUzsW84F0LISMJC1KdvQ&amp;number=7&amp;team_id=46&quot;) {
              let session = URLSession(configuration: .default)
              let task = session.dataTask(with: url) { (gettingInfo, response, error) in
                  if error == nil {
                      let decoder = JSONDecoder()
                      if let safeData = gettingInfo {
                          do {
                              let results = try decoder.decode(Results.self, from: safeData)
                              DispatchQueue.main.async {
                                  self.posts = results.data
                                  self.test = results.data[0].away_name
                                  self.test2 = results.data[0].home_name
                              }
                          } catch {
                              print(error)
                          }
                      }
                  }
              }
              task.resume()
          }
      }
  }
  </code></pre>
  <p>Showing Widget:</p>
  <pre><code>import WidgetKit
  import SwiftUI
  import Intents
  
  struct Provider: IntentTimelineProvider {
      func placeholder(in context: Context) -&gt; SimpleEntry {
          SimpleEntry(date: Date(), configuration: ConfigurationIntent())
      }
  
      func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -&gt; ()) {
          let entry = SimpleEntry(date: Date(), configuration: configuration)
          completion(entry)
      }
  
      func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline&lt;Entry&gt;) -&gt; ()) {
          var entries: [SimpleEntry] = []
  
          // Generate a timeline consisting of five entries an hour apart, starting from the current date.
          let currentDate = Date()
          for hourOffset in 0 ..&lt; 5 {
              let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
              let entry = SimpleEntry(date: entryDate, configuration: configuration)
              entries.append(entry)
          }
  
          let timeline = Timeline(entries: entries, policy: .atEnd)
          completion(timeline)
      }
  }
  
  struct SimpleEntry: TimelineEntry {
      let date: Date
      let configuration: ConfigurationIntent
  }
  
  struct WidgetNeuEntryView : View {
      
      @ObservedObject var networkManager = NetworkManager()
      var entry: Provider.Entry
      var body: some View {
          Text(networkManager.test)
      }
  }
  
  @main
  struct WidgetNeu: Widget {
      let kind: String = &quot;WidgetNeu&quot;
  
      var body: some WidgetConfiguration {
          IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
              WidgetNeuEntryView(entry: entry)
          }
          .configurationDisplayName(&quot;My Widget&quot;)
          .description(&quot;This is an example widget.&quot;)
      }
  }
  
  struct WidgetNeu_Previews: PreviewProvider {
      static var previews: some View {
          WidgetNeuEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent()))
              .previewContext(WidgetPreviewContext(family: .systemSmall))
      }
  }
  </code></pre>
  <p><code>networkManager.test</code> should be shown as text but as I said it is blank.</p>