NSNotificationCenter trapping and tracing all NSNotifications

前端 未结 5 647
傲寒
傲寒 2020-12-12 13:21

For some better understanding on what happens “under the hood”, I would love to do a complete trace of any notifications happening within my application.

Naïve as I

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 13:56

    For debugging purposes, I find that a breakpoint is actually better than adding code to the project. However, @Till's solution didn't seem to work for me. I found another solution online, and tweaked it a bit.

    Symbolic Breakpoint

    • Symbol: -[NSNotificationCenter postNotificationName:object:userInfo:]
    • Condition: ((NSRange)[$arg3 rangeOfString:@"^(_|NS|UI)" options:1024]).length == 0
    • Action: Debugger Command po $arg3
    • Automatically continue after evaluating actions

    Notes:

    • The condition is preventing any notifications that begin with _, NS, or UI from being displayed.
    • 1024 refers to NSRegularExpressionSearch, which doesn't seem to be available for that breakpoint.
    • I use .length == 0 instead of .location == NSNotFound because NSNotFound seems to evaluate to a different value (-1 or (NSUInteger)18446744073709551615) than the returned value in this breakpoint (9223372036854775807).

提交回复
热议问题