Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printable string interpolation not working

Given the following test code, why aren't the string interpolations \(t1) and \(t2) working? Renaming description causes the compiler to fail with "Type 'Test' does not conform to protocol 'Printable'" and description obviously works given the second println of each test.

enum Test: Printable {
    case A
    case B(Int)

    var description: String {
        switch self {
        case .A:
            return ".A"
        case let .B(value):
            return ".B: value = \(value)"
        }
    }
}

let t1 = Test.A
let t2 = Test.B(-100)

println("t1 = \(t1)")       // prints "t1 = (Enum Value)"
println(t1.description)     // prints ".A"

println("t2 = \(t2)")       // prints "t2 = (Enum Value)"
println(t2.description)     // prints ".B: value = -100"
like image 581
Price Ringo Avatar asked Sep 25 '14 21:09

Price Ringo


1 Answers

Note that enums being printed as (Enum Value) is a known bug in Swift version 1.0 (swift-600.0.51.3). It will be fixed in a future release.

like image 100
AlBlue Avatar answered Nov 17 '22 23:11

AlBlue