Why can not he show anything in the playground at Swift 2?

advertisements

I try to use spriteKit to show something in playground in assistant editor. However, nothing showed. Below is the code. And if any one can show the results (a blue rectangle), please inform me. If not, please figure out where the problem is.

import UIKit
import SpriteKit

let view:SKView = SKView(frame: CGRectMake(0, 0, 1000, 800))
let scene:SKScene = SKScene(size: CGSizeMake(1000, 800))
scene.scaleMode = SKSceneScaleMode.AspectFit

let blueBox: SKSpriteNode = SKSpriteNode(color: UIColor.blueColor(), size: CGSizeMake(300, 300))
blueBox.position = CGPointMake(512, 384)
scene.addChild(blueBox)

view.presentScene(scene)


You can see the current state of a view by clicking the QuickLook (eye) or circled-plus button in the sidebar. But to see your SpriteKit scene animate, you probably want a live view. For that, you need the XCPlayground framework.

import XCPlayground
XCPShowView("my SpriteKit view", view)

For details, read up on Exploring and Evaluating Swift Code in a Playground in Xcode Help or watch WWDC 2014 session 408: Swift Playgrounds.