Xcode LLDB Print Statements Fail - NSUndoManager
Asked Answered
Y

5

29

I have a breakpoint set and want to print my UITextField's superview. I type po myTextField.superview but I receive the following error:

error: instance method 'undoManager' has incompatible result types in different translation units ('id' vs. 'NSUndoManager *')
note: instance method 'undoManager' also declared here
error: 1 errors parsing expression

What does this mean and how can I print my superview? I found a link that provides a janky workaround in code: http://openradar.io/15890965, but I would like a better solution.

Yammer answered 9/6, 2014 at 17:27 Comment(2)
Same story here: I try po tableView.gestureRecognizers on a category of UITableView.Recluse
I have seen this error many times when trying to po frame, bounds, recursiveDescription, constraints, etc. (only built-in methods). Seems to be a crippling xcode/lldb bug.Viridis
Y
2

People of the world: I have an answer!

To dodge all UIKit errors: Before typing your po statement, type the line -- expr @import UIKit

If you want to turn this on for your app globally, then add the following breakpoint in your app delegate:

enter image description here

Thanks to Craig Hockenberry and Steve Streza for the update (found here).

Yammer answered 17/5, 2015 at 21:36 Comment(1)
This article tells you how to turn this on for all projects: merowing.info/2015/12/…Yammer
C
1

The solution I use to prevent this error while debugging is to explicitly cast everything.

In your case I would do

po [(UITextField *)myTextField superView]
Cal answered 11/8, 2014 at 17:18 Comment(2)
From initial testing, this seems to work for me. However, the 2nd comment in the link above (openradar.io/15890965) claims that it happens for them, even when explicitly casting. Anyone else want to chime in?Yammer
I tried explicitly casting and still get this error. e.g. po (NSString *)[((IBAdBannerView *)adView) recursiveDescription]Clupeid
T
1

Do you have any custom accessor methods for 'myTextField'? I have seen this same issue a number of times and it is usually caused by the po trying to print a property for an object that gets initialized the first time its getter is called. For example, if I try to run 'po self.imageView.contentMode' on a UITableViewCell I get that same error. Try moving your breakpoint to a point in the code where you know that 'myTextField' has been fully initialized.

Thickwitted answered 14/8, 2014 at 15:57 Comment(1)
I do not have a custom accessor method for myTextField. Good thought though.Yammer
F
0

Does myTextField really point to a UITextField? That's one reason this error will show up. For instance, the following code will compile, and if I set a breakpoint on the third line, I can enter po b.superview to reproduce the error you saw.

NSString *a = @"not a view";
UITextField *b = (UITextField *)a;
UIView *view = b.superview;

Try typing po [myTextField class] at your LLDB prompt to see if it's actually a UITextField. It could be another type of object, or nil.

Female answered 5/7, 2014 at 3:39 Comment(1)
myTextField does point to a UITextField (through an outlet).Yammer
C
0

I got this error in Xcode 5.1.1 and fixed it by quitting Xcode 5.1.1 and trying Xcode 6. Rebooting Xcode 5.1.1 for Xcode 5.1.1 may also work for some people.

Clupeid answered 7/10, 2014 at 21:13 Comment(1)
I have not yet found this error with Xcode 6, so Apple may have fixed it. It'll take some more time before we're sure though.Yammer

© 2022 - 2024 — McMap. All rights reserved.