在 Swift 中继承 SCNScene - 覆盖 init [英] Subclassing SCNScene in Swift - override init

查看:51
本文介绍了在 Swift 中继承 SCNScene - 覆盖 init的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Swift 的 Xcode 6 中遇到了一些编译器错误,我很难理解.我试图通过继承 SCNScene 来创建一个场景,但在初始化程序上不断出错.我的代码的基本结构是:

I'm getting some compiler errors in Xcode 6 using Swift which I have a hard time wrapping my head around. I'm trying to create a scene by subclassing SCNScene, but keep getting errors on the initialisers. The basic structure of my code is:

class SpaceScene: SCNScene {
    override init(named: String) {
        super.init(named: named)
    }
}

这会导致第 2 行出现错误消息初始化程序不会覆盖其超类中的指定初始化程序",尽管 SCNScene 显然有这样的初始化程序.我想我错过了一些基本的东西 - 有什么见解吗?

This results in an error on line 2 with the message "Initializer does not override a designated initializer from its superclass", although SCNScene clearly has such an initialiser. I think i'm missing something basic - any insights?

推荐答案

XCode 6.1 上,应该做到以下几点:

On XCode 6.1, the following should do it:

class SpaceScene : SCNScene {

override init() {
    super.init()
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}
}

这篇关于在 Swift 中继承 SCNScene - 覆盖 init的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆