implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC

吃可爱长大的小学妹 提交于 2019-12-03 02:18:14

问题


What does this mean and what alternative do I have?

implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC

I am porting an Xcode3 project to iOS5 wich uses AudioSessionInitialize like this

AudioSessionInitialize(NULL, NULL, NULL, self);

where self here is a ViewController.


回答1:


You can't do implicit casts to void* anymore, AudioSessionInitialize(NULL, NULL, NULL, objc_unretainedPointer(self)); should do the trick.

EDIT: Historical point, the answer above was from before the __bridge casts were finalized. In modern code the correct answer is that provided by @KazukiSakamoto, AudioSessionInitialize(NULL, NULL, NULL, (__bridge void*)self);




回答2:


  • Automatic Reference Counting - 3.2.4. Bridged casts

You should use __bridge cast for it.

AudioSessionInitialize(NULL, NULL, NULL, (__bridge void *)self);


来源:https://stackoverflow.com/questions/6868130/implicit-conversion-of-an-objective-c-pointer-to-void-is-disallowed-with-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!