在了解reflect()
动态学习类型之后,我开始使用它并得到这个奇怪的崩溃:
# swift -version
Swift version 1.1 (swift-600.0.56.1)
Target: x86_64-apple-darwin14.1.0
# swift
Welcome to Swift! Type :help for assistance.
1> println(reflect({1}))
Swift._OpaqueMirror
2> reflect({1})
Segmentation fault: 11
但是:
1> reflect({1}).dynamicType
$R0: MirrorType.Type = Swift._OpaqueMirror
此行为是可重复的,硬件/操作系统(10.10.2)运行良好。评估期间还有一个明显的暂停,就好像堆栈或缓冲区溢出一样。诸如使用分配给闭包的变量和反映变量的变化也会崩溃。最后:在lldb中运行swift使其能够正常输出!
[...]
(lldb) c
Process 3322 resuming
Welcome to Swift! Type :help for assistance.
1> reflect({"a"})
reflect({"a"})
$R0: _OpaqueMirror = {
data = {
owner = {}
ptr = {}
metadata = 0x07fad7e8ffffff40
}
}
任何见解?
答案 0 :(得分:1)
看起来这已在Swift 1.2测试版中得到修复:
% swift -v
Apple Swift version 1.2 (swiftlang-602.0.37.3 clang-602.0.37)
Target: x86_64-apple-darwin14.1.0
Welcome to Swift version 1.2. Type :help for assistance.
1> println(reflect({1}))
Swift._OpaqueMirror
2> reflect({1})
$R0: _OpaqueMirror = {
data = {
owner = {}
ptr = {}
metadata = 0x0000000100700068
}
}
3>