I get this Error in swift
'BlockColor' cannot be constructed because it has no accessible initializers
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)))!
}
}
I got an error in this line
return BlockColor(rawValue:Int(arc4random_uniform(NumberOfColors)))!
I have review my code many times but I couldn't find where is the error
I got the same error. My mistake was that i didn't mention any return (Int) type for enum method ( enum BlockColor: Int ). after initialization of Int return type. Its Works now.
problem solved :) it seem like the problem was with my Xcode 6.0. the code work fine in Xcode 6.2 beta.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.