The accepted answer is a screen-shot, not in-line code, and it shows how to do this pre Xcode 8, so I don't think it's a good answer.
Here is an updated answer For Xcode 8:
There are several steps:
You need to import PlaygroundSupport
import PlaygroundSupport
You need to set PlaygroundPage.current.needsIndefiniteExecution to true:
PlaygroundPage.current.needsIndefiniteExecution = true
You need to add the view hierarchy you want to display to the liveView:
PlaygroundPage.current.liveView = container
The whole playground might look like this:
import UIKit
import PlaygroundSupport
let container = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
view.backgroundColor = UIColor.red
container.addSubview(view)
PlaygroundPage.current.liveView = container
PlaygroundPage.current.needsIndefiniteExecution = true
Finally, you need to see the live view you just created. On my copy of Xcode 8 (release version) If I try to select view menu>assistant editor>Show Assistant Editor Xcode crashes, every time.
I have to hover my mouse on the right side of the screen in the box to the right of the code, on the line where I create the container view. I see a little eye icon, and if I click on that, it shows the live view without crashing.