Xcode 8 playground live view doesn't work
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.
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
iOS Playground doesn't show UI preview
Open the preview panel: View > Assistant Editor > Show Assistant Editor
Then in your code:
import PlaygroundSupport
PlaygroundPage.current.liveView = view
Don't forget to give your view a visible frame.
Ps: after Xcode 9, you can create a playground with default view
Xcode 8.3.2 playground live view rendering doesn't work
You need to enable the assistant editor to see the results.
View > Assistant Editor > Show Assistant Editor
Also see here:
iOS Playground doesn't show UI preview
Fix live view issues
Try this code!!
var image = UIImage(named: "m.jpg")
let imageView = UIImageView()
imageView.image = image
imageView.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
imageView.backgroundColor = .black
PlaygroundPage.current.liveView = imageView
Multiple Views In Xcode Swift Playground
In your playground file, you create your scene view like this:
let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 640, height: 480))
let myScene = FirstView(fileNamed: "MyPlayground")
if let scene = myScene {
scene.scaleMode = .aspectFill
sceneView.presentScene(scene)
}
PlaygroundSupport.PlaygroundPage.current.liveView = sceneView
And in your First View file, create your FirstView
class. Do not forget to put it as public:
import Foundation
import SpriteKit
public class FirstView: SKScene {
private var label : SKLabelNode!
open override func didMove(to view: SKView) {
// Get label node from scene and store it for use later
label = SKLabelNode(text: "first view")
label.position = view.center
addChild(label)
}
}
Related Topics
"This Class Is Not Key Value Coding-Compliant" Using Coreimage
Nstextfield Non-System-Font Content Clipped When Usessinglelinemode Is True
Why Is Inceptionv3 Machine Learning Model Not Recognized on My Project
Shorthand for Wrapping a Swift Variable in an Optional
Xcode 7 Cast from Xcuielement to Unrelated Type 'string' Always Fails While Fetching JSON
Apple Turicreate Always Return The Same Label
Swift Version Build Configuration
How to Mutate an Array in a Dictionary
What Was The Reason for Swift Assignment Evaluation to Void
Remove from Array of Anycancellable When Publisher Finishes
A Concise Way to Not Execute a Loop Now That C-Style for Loops Are Going to Be Removed from Swift 3
Decrypted String Always Returning Null
How to Create a Cocoapod with .Swift
Uidatepicker Show Only Sunday's Date Only