将CFTypeRef(aka const void *)发送到'void *'类型的参数会丢弃限定符 [英] sending CFTypeRef (aka const void*) to parameter of type 'void *' discards qualifiers

查看:596
本文介绍了将CFTypeRef(aka const void *)发送到'void *'类型的参数会丢弃限定符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码中引发警告。使用ARC。

A warning is raised in the following code. ARC is used.

if ( aAnim ) {
    [UIView beginAnimations:nil context:CFBridgingRetain([NSNumber numberWithInt:aOff])];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(postSpin:finished:toCCWCellOffset:)];
}


推荐答案

CFBridgingRetain 返回 CFTypeRef ,声明为 const void *

上下文参数[UIView beginAnimations:context:] void * (没有
const ),因此警告。

The context parameter of [UIView beginAnimations:context:] is a void * (without the const), hence the warning.

您可以使用 __ bridge_retained 来修复该警告:

You can fix that warning by using __bridge_retained instead:

[UIView beginAnimations:nil context:(__bridge_retained void *)[NSNumber numberWithInt:aOff]];

请注意,您必须平衡保留通过在不再使用
时释放上下文。例如,可以通过将所有权
转回Objective-C对象来在停止选择器中完成:

Note that you have to balance that retain by releasing the context when it is no longer used. This can for example be done in the "stop selector" by transferring the ownership back to an Objective-C object:

id obj = (__bridge_transfer id)context;

这篇关于将CFTypeRef(aka const void *)发送到'void *'类型的参数会丢弃限定符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆