在哪里
我在swift 中得到这个错误
无法构造"BlockColor",因为它无法访问初始化程序
import Foundation
import SpriteKit
let NumberOfColors: UInt32 = 6
enum BlockColor: Int, Printable {
case Blue = 0, Orange, Purple, Red, Teal, Yellow
var spriteName: String {
switch self {
case .Blue:
return "blue"
case .Orange:
return "orange"
case .Purple:
return "purple"
case .Red:
return "red"
case .Teal:
return "teal"
case .Yellow:
return "yellow"
}
}
var description: String {
return self.spriteName
}
static func random() -> BlockColor {
return BlockColor(rawValue:Int(arc4random_uniform(NumberOfColors)))!
}
}
我在这行中出错
return BlockColor(rawValue:Int(arc4random_uniform(NumberOfColors)))!
我已经检查了很多次我的代码,但我找不到错误
我得到了同样的错误。我的错误是,我没有提到enum方法的任何返回(Int)类型(enum BlockColor:Int)。在初始化Int返回类型之后。它现在起作用了。
问题解决了:)这个问题似乎是我的Xcode 6.0造成的。代码在Xcode 6.2测试版中运行良好。