6

I have an ordinary .sks file in Xcode9, TestScene.sks.

Of course, you need an SKView to "hold" an .sks.

If I manually construct the SKView in code in the usual way it works fine. (I've included a handy example of that at the bottom of this post.)

However, in X9 you can simply add a SKView in storyboard.

And then just choose the .sks file in the Attributes inspect....

enter image description here

But.

It does not work. I just get this error:

Main.storyboard: Class Unavailable Xcode.IDEInterfaceBuilder.CocoaTouch.SKView

What could the problem be?

SpriteKit.framework is included in Link Binary ...

what could be the reason?


Point 1: for the record, how to manually add in code:

func manuallyAddSceneInCode() {

    let sk: SKView = SKView()
    sk.frame = view.bounds
    sk.backgroundColor = .clear
    view.addSubview(sk)

    let scene = SKScene(fileNamed: "TestScene")!
    scene.scaleMode = .aspectFit
    scene.backgroundColor = .clear

    sk.presentScene(scene)
}

Point 2 - as Knight asks below. If you "just drop a regular UIView and custom class it to SKView" - of course, you then don't get any of the "custom controls" for the class. (Just as if you say custom class a normal UIView to UILabel - it does not "work like" a UILabel in storyboard.)


Point 3 - Knight seems to have hit a nail on the head, indeed the class mentioned in the error is "Xcode.IDEInterfaceBuilder...." what the heck is that?


Point 4, I just tried in 9.0.1, same problem.

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • huge bounty coming on this ! – Fattie Oct 17 '17 at 12:31
  • 1
    Why is the class `Xcode.IDEInterfaceBuilder.CocoaTouch.SKView` That is weird. What happens when you just drop a regular `UIView` and custom class it to `SKView` – Knight0fDragon Oct 17 '17 at 13:29
  • @Knight0fDragon, interesting points - see edits. pls note massive bounty. tell your friends! :) – Fattie Oct 17 '17 at 17:24
  • Please don't add messages like "massive bounty" to the title of your question. The bounty is already displayed in question listings while it's active; there's no need to repeat it. –  Oct 17 '17 at 20:48
  • @Fattie No, I think you're missing the point. That information does not belong in the title of the question. –  Oct 17 '17 at 23:08
  • 1
    I can't find any way to get it to work, I am guessing it is a bug by Apple (There are so many bugs by them lately it is disgusting,) so I would recommend filing a bug report so that they are aware this is happening. – Knight0fDragon Oct 19 '17 at 13:38
  • Delete your storyboard and rebuild it, I don't see the issue when I did that – Knight0fDragon Oct 19 '17 at 21:34
  • sure; will try that .. – Fattie Oct 19 '17 at 21:46
  • Did remaking it work? – Knight0fDragon Oct 23 '17 at 19:48

2 Answers2

1

I just replicated your error. The problem seems to be related to the deployment target. If I deploy to iOS 9.0, I get your error, if I increase the deployment target to iOS 10, the error goes away. I guess storyboard only supports it that far.

EDIT:

I uploaded my demo project you can check:

https://github.com/seriouscyrus/SCSpriteKitStoryboard

In the Master branch, the deployment target is 9.0 and you get the error when you try to build, in the iOS10Deployment branch it is fixed. No need to restart anything.

Additionally my error gives more information, "SKView before iOS 10.0 (NSCoding was broken in previous versions".

George Brown
  • 1,134
  • 10
  • 25
  • We did not have time to utterly investigate it, but this does seem to be the resolution. In short it is just a problem in Xcode, at this time (late 2017) – Fattie Oct 29 '17 at 16:05
0

Could it be that you're not importing Spritekit into the view controller that owns the view? This needs to be done with GLKit views, even if you link the library.

(At least in obj-c anyway)

Fattie
  • 27,874
  • 70
  • 431
  • 719
George Brown
  • 1,134
  • 10
  • 25