In my Swift playground, I entered the following code to test the live view feature:
let view = UIView()
PlaygroundPage.current.liveView = view
But for some reason the live view doesn't display on the right in the Assistant Editor. Initially I thought that Xcode wasn't finished running the playground. But I waited and waited and it still doesn't show.
Screenshot:
Any help?
I had this same exact issue. I found a temporary solution.
What I noticed is that if I opened more than one Xcode project it would cause this error. So Just completely quit xcode (command Q) and only open the live playground you are trying to work on and it should work.
Make sure you have the following imports and you might want to give it a frame and color just to make sure it is actually working since your view does not have a frame or color. This code works for me.
import UIKit
import PlaygroundSupport
let view = UIView()
view.backgroundColor = .white
view.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
PlaygroundPage.current.liveView = view
For some users who come here, you may need to turn on live view in XCode
In Xcode 9.0 as well as having:
PlaygroundPage.current.needsIndefiniteExecution = true
You have to manually open the assistant editor then the playground with current focus will show the UIView.
I had the same issue as well and the following line of code fixed it for me:
PlaygroundPage.current.needsIndefiniteExecution = true
Setting a live view is supposed to auto-enable it for you, but for me it wasn't doing it. Must be a bug in Xcode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With