Playgrounds: Swift SpriteKit code is not getting live view

import Cocoa
import SpriteKit
import PlaygroundSupport
let view:SKView = SKView(frame: CGRect(x: 0, y: 0, width: 1024, height: 768))
let scene:SKScene = SKScene(size: CGSize(width: 1024, height: 768))
scene.scaleMode = SKSceneScaleMode.aspectFit
view.presentScene(scene)
view.showsFPS = true
let redBox:SKSpriteNode = SKSpriteNode(color: SKColor.red, size: CGSize.init(width: 300, height: 300))
redBox.position = CGPoint(x: 512, y: 384)
redBox.run(SKAction.repeatForever(SKAction.rotate(byAngle: 6, duration: 2)))
scene.addChild(redBox)
PlaygroundPage.current.liveView = view
PlaygroundPage.current.needsIndefiniteExecution = true


I have the following code but it doesn't display the spinning red square as expected. What do I do?

Replies

Did you show the assistant editor (View > Assistant Editor > Show Assistant Editor)? I pasted your code into a playground (OS X 10.11.6, Xcode 8.0b6, macOS playground) and I got a spinning red square once I showed that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I showed the assistant editor but the Xcode Playground got into an infinite loop with the running command and never displayed the spinning red box with Xcode 8.0b6 and OS X 10.12 Beta (16A313a). How can I solve this problem? Is there a way to find out what is happening with Playgrounds? It seems very flaky on my machine.

How can I solve this problem?

I don’t have any suggestions here, alas. I did what you did and it worked just fine.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I turned on the issues log in Xcode 8 GM Seed Playgrounds and this is output I got:


Playground execution failed: error: Couldn't lookup symbols:
  __TMaC17PlaygroundSupport14PlaygroundPage
  __TFC17PlaygroundSupport14PlaygroundPages24needsIndefiniteExecutionSb
  __TFC17PlaygroundSupport14PlaygroundPageau7currentS0_
  __TWPCSo6NSView17PlaygroundSupport22PlaygroundLiveViewableS0_
  __TFC17PlaygroundSupport14PlaygroundPages8liveViewGSqPS_22PlaygroundLiveViewable__
* thread #1: tid = 0x2eb451, 0x000000010fa5b360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x000000010fa5b360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground
    frame #1: 0x000000010fa5922a com.apple.dt.Xcode.PlaygroundStub-macosx`-[PlaygroundViewBridgeService execute] + 90
    frame #2: 0x00007fffad01602c CoreFoundation`__invoking___ + 140
    frame #3: 0x00007fffad015eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #4: 0x00007fffad02f376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #5: 0x00007fffc021f18d ViewBridge`__68-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:]_block_invoke + 47
    frame #6: 0x00007fffc023078b ViewBridge`__runAnimationGroup_block_invoke + 21
    frame #7: 0x00007fffab56b7e3 AppKit`+[NSAnimationContext runAnimationGroup:] + 58
    frame #8: 0x00007fffaacc5776 AppKit`+[NSAnimationContext runAnimationGroup:completionHandler:] + 85
    frame #9: 0x00007fffc0230767 ViewBridge`runAnimationGroup + 303
    frame #10: 0x00007fffc021ec94 ViewBridge`+[NSVB_View _animateWithAttributes:animations:completion:] + 507
    frame #11: 0x00007fffc021f10f ViewBridge`-[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 156
    frame #12: 0x00007fffad0149ea CoreFoundation`___forwarding___ + 538
    frame #13: 0x00007fffad014748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #14: 0x00007fffad01602c CoreFoundation`__invoking___ + 140
    frame #15: 0x00007fffad015eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #16: 0x00007fffad02f376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #17: 0x00007fffc01ed22b ViewBridge`-[NSVB_QueueingProxy forwardInvocation:] + 327
    frame #18: 0x00007fffad0149ea CoreFoundation`___forwarding___ + 538
    frame #19: 0x00007fffad014748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #20: 0x00007fffad01602c CoreFoundation`__invoking___ + 140
    frame #21: 0x00007fffad015eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #22: 0x00007fffad02f376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #23: 0x00007fffad0149ea CoreFoundation`___forwarding___ + 538
    frame #24: 0x00007fffad014748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #25: 0x00007fffad01602c CoreFoundation`__invoking___ + 140
    frame #26: 0x00007fffad015eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #27: 0x00007fffad02f376 CoreFoundation`-[NSInvocation invokeWithTarget:] + 54
    frame #28: 0x00007fffad0149ea CoreFoundation`___forwarding___ + 538
    frame #29: 0x00007fffad014748 CoreFoundation`__forwarding_prep_0___ + 120
    frame #30: 0x00007fffad01602c CoreFoundation`__invoking___ + 140
    frame #31: 0x00007fffad015eb1 CoreFoundation`-[NSInvocation invoke] + 289
    frame #32: 0x00007fffc0234e28 ViewBridge`withHintInProgress + 487
    frame #33: 0x00007fffc0234b57 ViewBridge`__deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
    frame #34: 0x00007fffc01c6202 ViewBridge`+[NSViewServiceApplication withHostPID:invoke:] + 46
    frame #35: 0x00007fffc0234a1a ViewBridge`__deferNSXPCInvocationOntoMainThread_block_invoke + 179
    frame #36: 0x00007fffc0234607 ViewBridge`__deferBlockOntoMainThread_block_invoke_2 + 544
    frame #37: 0x00007fffad0383ac CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #38: 0x00007fffad019424 CoreFoundation`__CFRunLoopDoBlocks + 356
    frame #39: 0x00007fffad018f66 CoreFoundation`__CFRunLoopRun + 1878
    frame #40: 0x00007fffad0185b4 CoreFoundation`CFRunLoopRunSpecific + 420
    frame #41: 0x00007fffac5b9f6c HIToolbox`RunCurrentEventLoopInMode + 240
    frame #42: 0x00007fffac5b9da1 HIToolbox`ReceiveNextEventCommon + 432
    frame #43: 0x00007fffac5b9bd6 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame #44: 0x00007fffaacaf5f5 AppKit`_DPSNextEvent + 1093
    frame #45: 0x00007fffab3bf8eb AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1637
    frame #46: 0x00007fffc01c747a ViewBridge`-[NSViewServiceApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 102
    frame #47: 0x00007fffaaca3fbd AppKit`-[NSApplication run] + 926
    frame #48: 0x00007fffaac6ea8a AppKit`NSApplicationMain + 1237
    frame #49: 0x00007fffc22ad8b3 libxpc.dylib`_xpc_objc_main + 775
    frame #50: 0x00007fffc22ac2d0 libxpc.dylib`xpc_main + 494
    frame #51: 0x00007fffc01f16b9 ViewBridge`-[NSXPCSharedListener resume] + 16
    frame #52: 0x00007fffc01cc2c9 ViewBridge`NSViewServiceApplicationMain + 3022
    frame #53: 0x000000010fa5b3a2 com.apple.dt.Xcode.PlaygroundStub-macosx`main + 34
    frame #54: 0x00007fffc204a255 libdyld.dylib`start + 1
    frame #55: 0x00007fffc204a255 libdyld.dylib`start + 1


Can someone parse this and make sense of this because I don't get a rotating red square?

Please file a bug about this, making sure to attach a playground that exhibits this brokenness to that bug. Then post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I just read your complaint to the Swift mailing list, and was so free to test your code in the final version of Xcode 8, and I could see the turning square. 😉