将CFTypeRef(aka const void *)发送到'void *'类型的参数会丢弃限定符 [英] sending CFTypeRef (aka const void*) to parameter of type 'void *' discards qualifiers
问题描述
以下代码中引发警告。使用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屋!