Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoint for "Warning: Attempt to present * on * which is already presenting *"

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?

like image 449
smat88dd Avatar asked Aug 31 '16 09:08

smat88dd


1 Answers

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.

like image 77
Cristik Avatar answered Oct 02 '22 23:10

Cristik