I have an app using UrlSession
in Swift Playgrounds for iPad, and everything worked great.
I opened the same code in Swift Playgrounds for Mac, and the line:
let (data, _) = try await URLSession.shared.data(from: url)
silently fails everytime. I exported a small snippet to a playground in Mac, and found that adding:
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
At the beginning of the script fixes this in the playground. I am wondering if there is a way to move this code to the app version and get this up and running on the Mac? Or maybe this code was never designed to run on a Macbook?
I started from: https://www.hackingwithswift.com/forums/swiftui/urlsession-shared-data-from-url-fails-in-swift-playgrounds-for-mac/14987
in the playground, it is clear to me where needsIndefiniteExecution = true
goes, simply at the top of the script. In the app I am making, I don’t know where it goes. When I put it at the top of the file, it complains about not being able to run in a global scope. Is there a difference between the playground and the app (made in Swift playgrounds)?