Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String interpolation of an enum produces "unknown()" string

Tags:

swift

xcode10

Simple enum and interpolation:

enum Test {
    case test1
    case test2
    case test3
}

let a = Test.test1
let b = "\(a)"

From debug window I get:

a = (Test) test1
b = (String) "unknown()"

The problem is that this occurs in my project but not in a playground.

In project:

in project

In playground:

in playground

In log I get:

SWIFT RUNTIME BUG: unable to find field metadata for type 'ProjectName.(unknown context at 0x10672213c).Test'

What can be a problem? Project target iOS is 9. I did convert project to swift 4.2. I had this issue on XCode 10 betas and was hoping it will get fixed, but I guess it's not an IDE or Swift problem.

like image 733
Borys T Avatar asked Sep 18 '18 18:09

Borys T


1 Answers

You need to make sure the "Reflection Metadata Level" build setting is enabled:

enter image description here

The description of this build setting can be found here:

Reflection Metadata Level (SWIFT_REFLECTION_METADATA_LEVEL)

This setting controls the level of reflection metadata the Swift compiler emits.

  • All: Type information about stored properties of Swift structs and classes, Swift enum cases, and their names, are emitted into the binary for reflection and analysis in the Memory Graph Debugger.
  • Without Names: Only type information about stored properties and cases are emitted into the binary, with their names omitted. -disable-reflection-names
  • None: No reflection metadata is emitted into the binary. Accuracy of detecting memory issues involving Swift types in the Memory Graph Debugger will be degraded and reflection in Swift code may not be able to discover children of types, such as properties and enum cases. -disable-reflection-metadata
like image 76
Cristik Avatar answered Sep 28 '22 14:09

Cristik