xie bo chen xie bo chen - 1 year ago 113
Swift Question

Type () does not conform to an undefined protocol

let NumberOfColor: UInt32 = 6

enum BlockColor:Int, CustomStringConvertible{
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 .Yellow:
return "yellow"
static func random() -> BlockColor{
return BlockColor(rawValue:Int(arc4random_uniform(NumberOfColor)))!

and mistake is"enum BlockColor:Int, CustomStringConvertible{...}"

Type 'BlockColor' does not conform to protocol 'CustomStringConvertible'

I try to make the game by swift,but i have a problem with the code
Can anyone tell me why there happen this mistake?
(My English is not good, that is my first question, thank everyone

this question have be done , thanks.
but have same question

class Block: Hashable, CustomReflectable{

let color:BlockColor

var column: Int
var row: Int
var sprite: SKSpriteNode?

var spriteName: String{
return color.spriteName

var hashValue: Int{
return self.column ^ self.row

init(column:Int, row:Int, color:BlockColor){
self.column = column
self.row = row
self.color = color

var description: String{
return "\(color): [\(column), \(row)]"

func == (lhs: Block, rhs: Block) -> Bool{
return lhs.column == rhs.column && lhs.row == rhs.row && lhs.color.rawValue == rhs.color.rawValue

Answer Source

Paste your code in a playground and read the error message

Swift.CustomStringConvertible:15:16: note: protocol requires property 'description' with type 'String'

Alternatively ⌘-click on CustomStringConvertible to figure out the required methods.

The error message means you have to implement the property description in the enum

var description : String {
   return "\(self.rawValue)"

PS: you can also simply replace spriteName with description

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download