1

Is it possible to construct custom views for complex objects?

Specifically I want to view the inner workings of a CGPath.

I've found the "view variable as" option with right clicking the variable in the debug view, and I've seen ways to view (eg) strings &tc with it, but I haven't found anything that helps me in this case.

Markers
  • 328
  • 1
  • 13

1 Answers1

1

po path in the debugger will print out all of the path's elements. UIBezierPath has quick look support in the debugger, where you can hit space and view a drawing of it, but you have a CGPath. It seems that quick look support is not enabled for CF classes like CGPath.

But you're not stuck. If you right-click the variables list in the debugger (as shown here), and choose add expression, you can create a local UIBezierPath by typing this in the expression field:

UIBezierPath(cgPath: path)

or, if your debugger is in an Objective-C context:

[UIBezierPath bezierPathWithCGPath: path]

Your expression then shows up in the list, and you can press the space bar to see a visual representation.

This example shows how I have it set up in an Objective-C project:

enter image description here

Quick-looking the path shows this:

enter image description here

If po path isn't showing you any components (moveto, curveto etc) in the debugger, then I think you have an empty path, and your problem lies elsewhere. If otherPath is nil, then I get an invalid expression in the debugger when creating the bezier path.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • Ooooo, that looks good. However it gives me "Invalid Expression". The variable itself shows up as thePath = (void **) Summary Unavailable *thePath - (__NSCFType *) Summary Unavailable NSObject = Summary Unavailable isa = (Class) Summary Unavailable Does this mean the CGPath hasn't been allocated? This is part of why I want this in the first place. For complex (& hopefully irrelevant) reasons, I'm first trying to find out if the variable has even been allocated! Hmm, comments don't seem to format :( – Markers Feb 11 '22 at 15:55
  • However, I also get "Printing description of thePath->*thePath: Path 0x60000199c480:", which suggests there has been something allocated, surely? – Markers Feb 11 '22 at 16:17
  • Are you working in objective-c or swift? – jrturton Feb 11 '22 at 16:20
  • Objective-c... sorta. Actually in Kotlin, which interfaces with objective-c not Swift – Markers Feb 11 '22 at 16:28
  • I added an objective-c version. From your first comment it does sound like the path exists. – jrturton Feb 14 '22 at 09:28
  • That's encouraging (that you think the path exists), but this still doesn't show me any data. It's better. It doesn't immediately say "Invalid Expression", but it does after it assesses the variable. That Objective-C option should convert the CGPath? – Markers Feb 15 '22 at 11:35
  • 1
    I've added an example with a known-existing path, if you're seeing something other than that, then your first guess is correct and the path doesn't exist in the first place. A nil path shows the behaviour you're seeing. – jrturton Feb 16 '22 at 09:46
  • That's fabulous @jrburton, thank you. I still have a problem, so it may be in the way Kotlin interacts with pointer objects in Objective-C. The path is a property of a class, and when I modify the variable expression for this, I get "po testPath->thePath error: :1:9: member access into incomplete type 'ObjHeader' testPath->thePath" and it points to the "-" in "->", so unless there's something obviously wrong with that, I'll have to push the Kotlin folks harder. Thanks for your help – Markers Feb 16 '22 at 12:21
  • CGPaths aren't Objective-C NSObjects, but I don't know enough about how the referencing works, or how Kotlin deals with that, to offer any more help, sorry! – jrturton Feb 16 '22 at 17:03