Reputation: 1542
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.
Upvotes: 29
Views: 2378
Reputation: 1542
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:
Thanks to Craig Hockenberry and Steve Streza for the update (found here).
Upvotes: 2
Reputation: 3060
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.
Upvotes: 0
Reputation: 1627
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.
Upvotes: 1
Reputation: 1379
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]
Upvotes: 1
Reputation:
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
.
Upvotes: 0