UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

URLSession.shared.data(from: url) fails in Swift Playgrounds for Mac

Forums > SwiftUI

I followed this post on receiving and sending data with 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 beggining 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?

1      

The first line certainly should work in Xcode without the two playground lines.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.