记录一下一个总忘记的操作:

import UIKit
import PlaygroundSupport

let image = UIImage(named: "winnie.png")
let imageView = UIImageView(image: image)

PlaygroundPage.current.liveView = imageView

在 Xcode playground 中,如果引入 PlaygroundSupport 库,赋值 PlaygroundPage.current.liveView,可以将视图显示在右侧的预览框,也就是 Live View 中。

另外不只是 UIView,UIViewController 及其子类也是可以的,PlaygroundPage.current.liveView = controller 即可。