gpt4 book ai didi

swift - Xcode 7.3.1 Swift "initializer does not override a designated initializer from its superclass"错误

转载 作者:行者123 更新时间:2023-11-30 10:01:15 30 4
gpt4 key购买 nike

import Foundation
import SpriteKit

class HGHero: SKSpriteNode {

var body: SKSpriteNode!
var arm: SKSpriteNode!
var leftFoot: SKSpriteNode!
var rightFoot: SKSpriteNode!

错误出现在这里:

override init () {

我不确定发生了什么事。我正在尝试覆盖 SKSpriteNode 的默认 init。

super.init(texture: nil, color: UIColor.blackColor(), size:    
CGSizeMake(32,44))
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}

最佳答案

您只需删除 override 关键字即可。

class HGHero: SKSpriteNode {

var body: SKSpriteNode!
var arm: SKSpriteNode!
var leftFoot: SKSpriteNode!
var rightFoot: SKSpriteNode!

init() {
super.init(texture: nil, color: UIColor.blackColor(), size:
CGSizeMake(32,44))
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

Infact initializers are not inherited (like instead happen with methods or properties). So you do not override them.

只是一个注释

这些隐式未包装的选项

var body: SKSpriteNode!
var arm: SKSpriteNode!
var leftFoot: SKSpriteNode!
var rightFoot: SKSpriteNode!

非常危险。

关于swift - Xcode 7.3.1 Swift "initializer does not override a designated initializer from its superclass"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424405/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com