简单的枚举和内插:
enum Test {
case test1
case test2
case test3
}
let a = Test.test1
let b = "\(a)"
从调试窗口中我得到:
a = (Test) test1
b = (String) "unknown()"
问题是这发生在我的项目中,而不是在操场上。
在项目中:
在操场上:
在日志中,我得到:
SWIFT RUNTIME BUG: unable to find field metadata for type 'ProjectName.(unknown context at 0x10672213c).Test'
可能有什么问题?项目目标iOS为9。我确实将项目转换为Swift 4.2。我在XCode 10 beta上遇到了这个问题,希望它能解决,但我想这不是IDE或Swift的问题。
答案 0 :(得分:8)
You need to make sure the "Reflection Metadata Level" build setting is enabled:
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