13

Sometimes it happens that - from different places in code - we want to do UIViewController.presentViewController(a, b, c), and sometimes it happens that we are already presenting, in which case we get:

Warning: Attempt to present * on * which is already presenting *

Is it possible to break on this warning? How can I set a breakpoint for this?

smat88dd
  • 2,258
  • 2
  • 25
  • 38

1 Answers1

23

First things first, you need to set a symbolic breakpoint to -[UIViewController presentViewController:animated:completion:]. You can add this easily via Xcode's Add Symbolic Breakpoint feature.

Secondly, you need to set a condition so that the breakpoint is hit only when the view controller already presents something. Programatically speaking, this means that the presentedViewController property is non-nil. The trick here is to access the self implicit parameter passed to any method call, which can be done by using $arg1 (more details on that here). Once you have this, the rest is easy.

Here's how the breakpoint should look like:

Breakpoint
(source: cristik-test.info)

In summary:

Symbol: -[UIViewController presentViewController:animated:completion:]
Condition: [(UIViewController *)$arg1 presentedViewController] != nil

This works for Objective-C as well as Swift projects, since the UIViewController is (still) exporting its public methods as Objective-C symbols.

Cristik
  • 30,989
  • 25
  • 91
  • 127
  • Right! I was already thinking that I dont want to check the presentedViewController in code everywhere I call presentViewController, and oversaw that I can use that if-check as a condition for the breakpoint. Awesome! Just need to verify that it works. – smat88dd Aug 31 '16 at 12:15