Swift error: “Cannot find interface declaration for 'SKScene', superclass of”

China☆狼群 提交于 2019-12-23 17:26:52

问题


Disclaimer: I read through similar questions on SO, couldn't find a solution to my problem.

I want to add an subclass of SKScene to a project that did not previously use SpriteKit.

The project is a mixture of ObjC and Swift. The subclass is written in Swift.

What I did:

  1. Added SpriteKit.Framework by going to the project -> Build Phases -> Link Binary with Libraries .
  2. I created a swift class and had it inherit from SKScene.

Here is the new class:

import SpriteKit

class SnowScene: SKScene {
}

Note that the class is not references by anywhere else in the code.

When I compile my app, I get the error in the title. The error occurs in my -Swift.h file, which auto-exported the new class (I have no idea why).

SWIFT_CLASS("_TtC11MyCoolApp9SnowScene")
@interface SnowScene : SKScene
@end

Does anyone have any idea what am I doing wrong and how to circumvent this problem?


回答1:


I'm assuming you did import SpriteKit in your source file or you would have gotten an error in the Swift compile phase.

This sounds like a bug in Swift where it's not correctly detecting that you are using SpriteKit. Normally, these dependencies are detected and inserted at the top of -Swift.h in an import section, around line 88:

#if defined(__has_feature) && __has_feature(modules)
@import Foundation;
@import UIKit;
@import ObjectiveC;
...
#endif

If SpriteKit isn't in that list, you're looking at a compiler bug and should file a radar with Apple.

If you have a bridging header, you will notice that right below those imports is:

#import "/Users/.../...-Bridging-Header.h"

If not, you should add one. I believe adding a single Objective-C file will trigger Xcode to do the work for you.

Including the line #import <SpriteKit/SpriteKit.h> in your bridging header will ensure that SpriteKit gets imported before your class is declared.



来源:https://stackoverflow.com/questions/33809938/swift-error-cannot-find-interface-declaration-for-skscene-superclass-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!