Hi ! I am trying to run some async code before setting up the playground liveView, but I cannot figure out why it keeps crashing. I started up with a task I was waiting on the result before configuring the liveView, and now I am having all async work in a dedicated function, which seems to work fine : imageView has the correct width, and the line playground preview shows the image I am fetching online ! In both cases, I get the same result.
Would that error be obvious to anyone ?
import Foundation
import UIKit
import PlaygroundSupport
let image = try await getImage()
let imageView = UIImageView(image:image)
var liveView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 1050, height: 1050))
liveView.addSubview(imageView)
print("before set liveView. imageView.width = \(imageView.frame.width)")
PlaygroundPage.current.setLiveView(liveView) // crash here
the getImage prototype being :
public func getImage() async throws -> UIImage?
And the console output :
before set liveView. imageView.width = 960.0
Playground execution failed:
error: execution stopped with unexpected state.
error: Execution was interrupted, reason: shared-library-event.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.