15

I'm trying to debug an iOS app and I'm having problems with lldb in the simulator. Calling class methods doesn't seem to work. Instance methods work fine.

(lldb) po Category
<no result>
(lldb) po [Category class]
error: Couldn't prepare the expression for execution in the target
(lldb) po self
(TagsTableViewController *) $5 = 0x085585a0 <TagsTableViewController: 0x85585a0>

I've tried the 4.3 and 5.1 simulators but both exhibit the same issues.

Everything works fine when debugging on a device.

devioustree
  • 231
  • 2
  • 7
  • 3
    I'm thinking it might be a bug in lldb but I've found a workaround in the meantime. It's a little awkward but it works: `po [(Class)objc_getClass("ClassName") class]` – devioustree Mar 27 '12 at 10:36

2 Answers2

18

This works. Thanks to @devioustree who answered in a comment above.

Basic command is structured like this:

po [(Class)objc_getClass("ClassName") class]

To invoke someClassMethodHere:

po [[(Class)objc_getClass("ClassName") class] someClassMethodHere]
bentford
  • 33,038
  • 7
  • 61
  • 57
0

Adding this to expand on the accepted answer...

If you're trying to assign a new value to a variable in lldb like I was instead of just printing out the value then do something like this...

expr self.myArray = (NSArray*)[[(Class)objc_getClass("NSArray") class] arrayWithObjects:@"valueOne",@"valueTwo",@"etc",nil]
digitalHound
  • 4,384
  • 27
  • 27