Xcode 6.3& Swift错误:Objective-C方法' init'由隐式初始化程序' init()'定义这里

时间:2015-02-10 13:05:24

标签: xcode swift

我刚刚更新到Xcode 6.3 beta。它支持Swift 1.2,因此它使我的项目出现了很多错误。虽然我使用过"转换为Swift 1.2"功能,但它不能清除所有错误。比如这个错误:

import SpriteKit
class Score: Shape {
    convenience init() {
        self.init(name:"Score",imageName:"score")
        self.physicsBody!.categoryBitMask = scoreCategory
        light.lightColor = SKColor.greenColor()
        light.categoryBitMask = scoreLightCategory
    }
}

Xcode显示第3行有错误:初始化程序' init()'覆盖Objective-C方法' init'来自超类' SKSpriteNode&#39 ;; Objective-C方法' init'由隐式初始化程序' init()'定义这里

但是如果我添加这样的参数:

import SpriteKit

class Score: Shape {
    convenience init(args:Bool) {
        self.init(name:"Score",imageName:"score")
        self.physicsBody!.categoryBitMask = scoreCategory
        light.lightColor = SKColor.greenColor()
        light.categoryBitMask = scoreLightCategory
    }
}

但是" Objective-C方法' init'由隐式初始化程序' init()'定义这里"意思?我怎样才能优雅地解决这个问题?

PS:Shape类继承自SKSpriteNode class:

class Shape: SKSpriteNode {
    required init(coder: NSCoder) {
        fatalError("NSCoding not supported")
    }

    init(name:String,imageName:String){

        super.init(texture: SKTexture(imageNamed: imageName),color:SKColor.clearColor(), size: CGSizeMake(radius*2, radius*2))
        self.name = name
    } 
}

1 个答案:

答案 0 :(得分:0)

这是在Xcode 6.3 beta 2中解决的。清理构建文件夹并重建后,它运行时没有错误。