ARC: EXC_BAD_ACCESS when calling a method from inside a block, inside a delegate method

时间秒杀一切 提交于 2019-12-05 12:34:19

You need to copy blocks if they need to outlive the scope they were created in. Since dictionaryWithObjectsAndKeys: deals with objects in general and not specifically blocks, it doesn't know to copy them, so you must copy them before passing them to it.

NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:
                   //blows up after executing this
                   [^() { [AnotherClass staticMethod]; } copy], authURL,
                   [^() { NSLog(@"TODO");} copy], searchURL,
                   [^() { NSLog(@"TODO"); } copy], itemURL,
                   nil];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!