Is there a way to trap messages sent to nil in Objective-C?

前端 未结 2 1628
说谎
说谎 2021-02-20 06:12

I\'ve just been bitten by an annoying bug that was made obscure by the \"send message to nil is ok\" behaviour in Objective-C.

I\'ve seen Sending a message to nil?, and

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-20 06:52

    You could use a ObjC undocumented trick or dtrace (see the comments for the dtrace solution).

    pid$1::objc_msgSend:entry
    /arg0==0/
    {
      ustack();
    }
    

提交回复
热议问题