sending CFTypeRef (aka const void*) to parameter of type 'void *' discards qualifiers

跟風遠走 提交于 2019-12-19 21:48:22

问题


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:)];
}

回答1:


CFBridgingRetain returns a CFTypeRef which is declared as const void *.

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

You can fix that warning by using __bridge_retained instead:

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

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;


来源:https://stackoverflow.com/questions/17038376/sending-cftyperef-aka-const-void-to-parameter-of-type-void-discards-quali

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