Why don't work URLSession in Swift Widget

I create widget with temperature from my site. In standart program all work, but in Widget on result i see "0" (info from var)
Here code with mistake (DataProvider.swift)
Code Block
import Foundation
class DataProvider {
struct CurrencyJSON: Codable {
var temp : String
}
static func getTemp() -> String {
var dig : String = "0"
print ("1")
//on url this data: {temp:3.5}, this is my site, i can do anything format, may be make format: 3.5 (no json)?
URLSession.shared.dataTask(with: URL(string: "http://example.com/weather.php")! ) {(data, response, error) in
guard let data = data else { return }
do {
let res = try JSONDecoder().decode(CurrencyJSON.self, from: data)
dig=res.temp
print ("\(dig)")
} catch let error {
print("\(error)")
}
}.resume()
return dig
}
}

And on widget i see "0" (From this: var dig : String = "0"), why? Where i make mistake?

Here my struct Provider: TimelineProvider:
Code Block
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), myString: "...")
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), myString: "...")
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
print ("1")
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .second, value: hourOffset * 10, to: currentDate)!
let entry = SimpleEntry(date: entryDate, myString: DataProvider.getTemp())
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}


i make mistake?

Your getTemp() handles the asynchronous call in a bad manner and would never work even in non-widget apps.
Your dig has a valid value only inside the completion handler. return dig is executed before the completion handler is invoked.
(Please indent your code properly.)
Why don't work URLSession in Swift Widget
 
 
Q