Franco Solerio Franco Solerio - 5 months ago 19
Swift Question

Cannot inspect variables with "po" in my Swift 2 project using Xcode 7.3.1 - error loading helper function

When I run my Swift app in Xcode 7.3.1 (with standard Swift 2 compiler) and execution pauses at a breakpoint, I cannot inspect variables with

po
command. The first time I run
po exists
(
exists
is a non-optional Bool variable in current scope) I get a long error message (see below). From the second time I run the same command onwards, I receive
error loading helper function: (null)
message.

The app is compiled and run on the debug scheme, with no "deployment post processing" and None [-O0] optimization.

Variable contents appear correctly in the variable inspector panel of Xcode.

Same error appears with
po self
or any other variable both running on device and iOS simulator.

If I run a new clean project, debugging with
po
works correctly.




In current scope:

var exists: Bool = self.canRemoveAttachmentForEpisode(episode)
NSLog("Exists is now \(exists)") // Breakpoint is set here


This is what happens in the debugger panel:

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)

Answer

I solved the issue. The problem was I was redefining an existing protocol:

protocol MyCustomStringConvertible {}

extension MyCustomStringConvertible where Self: RawRepresentable, Self.RawValue == String {
   ..
}

I redefined CustomStringConvertible protocol, or maybe Apple's CustomStringConvertible didn't exist when I wrote my own version of it. Probably the protocol is only used by po when debugging, so the error never came out at runtime.

My only doubt is this: shouldn't the compiler alert me for redefining an existing protocol?