本文介绍了Objective-C SCNetworkReachabilityContext ARC转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将应用转换为使用自动引用计数时,我遇到了此错误:

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

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

ARC不允许将Objective-C指针隐式转换为'void *' / i>

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};

如何摆脱这个警告?

使用'objc_objectptr_t'(又名'const void *')表达式初始化'void *'会丢弃限定符

推荐答案

你应该可以将self(id)强制转换为void *而没有问题。

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

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

这篇关于Objective-C SCNetworkReachabilityContext ARC转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:30