Correct management of addObserverForName:object:queue:usingBlock:

后端 未结 4 552
礼貌的吻别
礼貌的吻别 2021-02-01 03:37

I\'m still new to blocks in objective-c and wondering if I have this psuedo code correct. I\'m not sure if it\'s enough to just remove the observer or if i have to call removeOb

4条回答
  •  故里飘歌
    2021-02-01 04:19

    The scope of the block doesn't have permission to release the scanner object. If you're not using garbage collection, removing the release and making the scanner autorelease ([[[Scanner alloc] init] autorelease]) should do the trick.

    You should also be able to safely move the call to removeObserver outside of the block.

    For the case of EXC_BAD_ACCESS: Entering bt in the console window after the application crashes will give you a backtrace, and should inform you where the error occurred.

提交回复
热议问题