Reputation: 61
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
Upvotes: 6
Views: 4203
Reputation: 103
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.
Upvotes: 9
Reputation: 61
problem solved :) it seem like the problem was with my Xcode 6.0. the code work fine in Xcode 6.2 beta.
Upvotes: 0