I spent two hours trying to make this simple code to work, with no luck.
我花了两个小时试图让这个简单的代码工作,没有运气。
What I did:
我做了什么:
- I put a resource in the Resources directory.
- I referenced the resource as
UImage(named: "resource.jpg")
我在Resources目录中放置了一个资源。
我将资源引用为UImage(命名为:“resource.jpg”)
This is not a duplicate question as the Playground settings went through a major change in 6.3.1
这不是一个重复的问题,因为Playground设置经历了6.3.1中的重大更改
However, nothing is showing up. Here's a snapshot of my screen. As you can see there's no playground indicator running.
然而,没有任何东西出现。这是我的屏幕快照。你可以看到没有游乐场指示器在运行。
2 个解决方案
#1
1
The biggest problem I see from your screenshot is that you don't even have the playground timeline open to see the results in the first place. The playground timeline is 1 column to the right of the playground gutter.
我从您的屏幕截图中看到的最大问题是,您甚至没有打开游乐场时间轴来查看结果。操场时间线位于操场天沟右侧1列。
To view the playground timeline you use the Assistant Editor from the upper right. It is the button with the icon depicting 2 interconnected rings, or from the menu bar View > Assistant Editor > Show Assistant Editor.
要查看游乐场时间轴,请使用右上角的“助理编辑器”。它是带有图标的按钮,描绘了2个相互连接的环,或者从菜单栏视图>助理编辑器>显示助手编辑器。
The second thing I figured out is that you have to put the UIImageView inside a regular UIView for the call to XCPShowView to work properly. See code below.
我想到的第二件事是你必须将UIImageView放在常规的UIView中,以便调用XCPShowView才能正常工作。见下面的代码。
import UIKit
import XCPlayground
let image = UIImage(named: "pd.jpg")
let imageView = UIImageView(image: image)
XCPShowView("view", imageView) // Console error.
let bounds = imageView.bounds
let view = UIView(frame: bounds)
view.backgroundColor = UIColor.lightGrayColor()
view.addSubview(imageView)
XCPShowView("view", view) // This works!
Screen shot of the whole thing:
整个屏幕截图:
#2
0
For displaying an image in Playground you have to import XCPlayground.
要在Playground中显示图像,您必须导入XCPlayground。
import UIKit
import XCPlayground
#1
1
The biggest problem I see from your screenshot is that you don't even have the playground timeline open to see the results in the first place. The playground timeline is 1 column to the right of the playground gutter.
我从您的屏幕截图中看到的最大问题是,您甚至没有打开游乐场时间轴来查看结果。操场时间线位于操场天沟右侧1列。
To view the playground timeline you use the Assistant Editor from the upper right. It is the button with the icon depicting 2 interconnected rings, or from the menu bar View > Assistant Editor > Show Assistant Editor.
要查看游乐场时间轴,请使用右上角的“助理编辑器”。它是带有图标的按钮,描绘了2个相互连接的环,或者从菜单栏视图>助理编辑器>显示助手编辑器。
The second thing I figured out is that you have to put the UIImageView inside a regular UIView for the call to XCPShowView to work properly. See code below.
我想到的第二件事是你必须将UIImageView放在常规的UIView中,以便调用XCPShowView才能正常工作。见下面的代码。
import UIKit
import XCPlayground
let image = UIImage(named: "pd.jpg")
let imageView = UIImageView(image: image)
XCPShowView("view", imageView) // Console error.
let bounds = imageView.bounds
let view = UIView(frame: bounds)
view.backgroundColor = UIColor.lightGrayColor()
view.addSubview(imageView)
XCPShowView("view", view) // This works!
Screen shot of the whole thing:
整个屏幕截图:
#2
0
For displaying an image in Playground you have to import XCPlayground.
要在Playground中显示图像,您必须导入XCPlayground。
import UIKit
import XCPlayground