当我在Xcode 7.3.1(使用标准的Swift 2编译器)中运行我的Swift应用程序并在断点处执行暂停时,我无法使用po
命令检查变量。我第一次运行po exists
(exists
是当前范围内的非可选Bool变量)我收到一条很长的错误消息(见下文)。从第二次开始运行相同的命令,我收到error loading helper function: (null)
消息。
应用程序在调试方案上编译和运行,没有“部署后处理”和无[-O0]优化。
变量内容在Xcode的变量检查器面板中正确显示。
同样的错误出现在设备和iOS模拟器上运行的po self
或任何其他变量。
如果我运行一个新的干净项目,使用po
进行调试可以正常工作。
目前的范围:
var exists: Bool = self.canRemoveAttachmentForEpisode(episode)
NSLog("Exists is now \(exists)") // Breakpoint is set here
调试器面板中会发生这种情况:
po exists
error loading helper function: <EXPR>:141:9: warning: '--' is deprecated: it will be removed in Swift 3
--maxItemCounter
^~
-= 1
<EXPR>:237:14: warning: '++' is deprecated: it will be removed in Swift 3
i++
^~
+= 1
<EXPR>:267:19: warning: 'init(start:end:)' is deprecated: it will be removed in Swift 3. Use the '..<' operator.
let rng = Range(start: si, end: ei.advancedBy(-1))
^
<EXPR>:280:9: warning: initialization of variable '$__lldb_error_result' was never used; consider replacing with assignment to '_' or removing it
var $__lldb_error_result = __lldb_tmp_error
~~~~^~~~~~~~~~~~~~~~~~~~
_
<EXPR>:89:41: error: 'CustomStringConvertible' is ambiguous for type lookup in this context
if let csc = (x as? CustomStringConvertible) {
^~~~~~~~~~~~~~~~~~~~~~~
Swift.CustomStringConvertible:13:17: note: found this candidate
public protocol CustomStringConvertible {
^
Castamatic.CustomStringConvertible:1:17: note: found this candidate
public protocol CustomStringConvertible {
^
<EXPR>:101:41: error: 'CustomStringConvertible' is ambiguous for type lookup in this context
if let csc = (x as? CustomStringConvertible) {
^~~~~~~~~~~~~~~~~~~~~~~
Swift.CustomStringConvertible:13:17: note: found this candidate
public protocol CustomStringConvertible {
^
Castamatic.CustomStringConvertible:1:17: note: found this candidate
public protocol CustomStringConvertible {
^
(lldb)
(lldb) po exists
error loading helper function: (null)
(lldb)
答案 0 :(得分:2)
我解决了这个问题。问题是我正在重新定义现有的协议:
protocol MyCustomStringConvertible {}
extension MyCustomStringConvertible where Self: RawRepresentable, Self.RawValue == String {
..
}
我重新定义了CustomStringConvertible协议,或者当我编写自己的版本时,Apple的CustomStringConvertible可能不存在。可能该协议仅在调试时由po
使用,因此错误永远不会在运行时出现。
我唯一的疑问是:编译器是否应该提醒我重新定义现有协议?
答案 1 :(得分:1)
我有类似的问题,但有不同的解决方案。我在此链接中使用了此解决方案:https://stackoverflow.com/a/32984193/2060180
如果它对某人有用,我会留在这里。