swift - 在 UIViewController 类中使用“视图”时,Swift Playground 崩溃
问题描述
我在 Swift Playgrounds 应用程序中有以下代码,但是当我运行它时,我收到错误“Problem Running Playground”。我一步一步地运行代码,它似乎在view.backgroundColor = UIColor.red
. 但是,这可以在 Xcode Playground 上完美执行。我的代码有问题还是这是 Swift Playgrounds 中的错误?
import UIKit
import PlaygroundSupport
class Test: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.red
}
}
PlaygroundPage.current.liveView = Test()
解决方案
是的,这是 2018 年 4 月 30 日发布的 Playgrounds 2.1 中的一个错误。在之前的版本中这不是问题。
由于某种原因,该视图在 viewDidLoad 中不存在,即使它应该存在。所以它崩溃了,因为它是零。
查看这篇文章,详细介绍问题和一些解决方法。
https://makeapppie.com/2018/05/07/bug-workaround-swift-playgrounds-for-ipad/
推荐阅读
- reactjs - 通过访问 this.state 在状态中设置索引
- r - 如何将 2D 数据帧转换为 3D 矩阵,保留行和列顺序
- code-coverage - 通过 CircleCI 中的赛普拉斯代码覆盖插件运行时,纽约报告失败并显示 ENOENT
- ruby-on-rails - 为什么我的多对多集合没有通过?
- python - 从 Python 到 SQL(Aginity、Netezza)的 CREATE/DROP 调用不起作用
- javascript - Vue-tables-2 options.hiddenColumns 不起作用
- python - 列表、字典和元组值
- php - WHMCS - 将客户名称和电子邮件添加到附属页面
- r - 有没有办法找到并删除 R 中分组 ID 的奇数行?
- snowflake-cloud-data-platform - Snowflake my_var 中的元组类型