Values descriptions format inconsistency

I'm getting this disparity when printing values:

enum E { case foo }
let value = E.foo
let a = "\(value)"    // "foo"
let b = "\([value])"  // "[AppName.E.foo]"

Shouldn't it be consistent:

  • either "AppName.E.foo" in the first place to match the second
  • or "[foo]" in the second place to match the first?
1 Like

Arrays always print their elements with String(reflecting:), mainly so that an array of strings has its elements clearly delimited.

1 Like

Same inconsistency between Optional and T:

struct S { var x = 42 }
var s: S = S()
var o: S? = S()
print(s) // S(x: 42)
print(o) // Optional(AppName.S(x: 42))

Aha, it has to do with whether the thing is at the top level or not:

struct D { var s = S() }
var d: D = D()
var r: D? = D()
print(d) // D(s: AppName.S(x: 42))
print(r) // Optional(AppName.D(s: AppName.S(x: 42)))