Objective-C SCNetworkReachabilityContext ARC conversion

这一生的挚爱 提交于 2019-12-12 10:52:12

问题


While converting an app to use Automatic Reference Counting I came across this error:

SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL};

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

This fixes the compiler error, but gives a warning:

SCNetworkReachabilityContext context = {0, objc_unretainedPointer(self), NULL, NULL, NULL};

How to get rid of this warning?

Initializing 'void *' with an expression of type 'objc_objectptr_t' (aka 'const void *') discards qualifiers


回答1:


You should be able to cast self (id) to a void * without problem.

SCNetworkReachabilityContext context = {0, ( void * )self, NULL, NULL, NULL};


来源:https://stackoverflow.com/questions/7151362/objective-c-scnetworkreachabilitycontext-arc-conversion

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