Xcode 8游乐场实时视图不起作用

时间:2023-01-23 21:33:31

In my Swift playground, I entered the following code to test the live view feature:

在我的Swift游乐场中,我输入以下代码来测试实时视图功能:

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.

但由于某种原因,实时视图不会显示在“助理编辑器”的右侧。最初我认为Xcode没有完成游乐场的运行。但我等待并等待它仍然没有显示。

Screenshot: Xcode 8游乐场实时视图不起作用

截图:

Any help?

有帮助吗?

3 个解决方案

#1


19  

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.

我注意到的是,如果我打开多个Xcode项目,它将导致此错误。所以,只需完全退出xcode(命令Q),只打开你正在尝试的实时游乐场,它应该可以工作。

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

Xcode 8游乐场实时视图不起作用

#2


8  

In Xcode 9.0 as well as having:

在Xcode 9.0中以及:

PlaygroundPage.current.needsIndefiniteExecution = true

You have to manually open the assistant editor then the playground with current focus will show the UIView.

您必须手动打开助理编辑器,然后当前焦点的操场将显示UIView。

#3


5  

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.

设置实时视图应该是为你自动启用它,但对我来说它没有这样做。必须是Xcode中的错误。

#1


19  

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.

我注意到的是,如果我打开多个Xcode项目,它将导致此错误。所以,只需完全退出xcode(命令Q),只打开你正在尝试的实时游乐场,它应该可以工作。

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

Xcode 8游乐场实时视图不起作用

#2


8  

In Xcode 9.0 as well as having:

在Xcode 9.0中以及:

PlaygroundPage.current.needsIndefiniteExecution = true

You have to manually open the assistant editor then the playground with current focus will show the UIView.

您必须手动打开助理编辑器,然后当前焦点的操场将显示UIView。

#3


5  

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.

设置实时视图应该是为你自动启用它,但对我来说它没有这样做。必须是Xcode中的错误。