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

后端 未结 1 1354
臣服心动
臣服心动 2021-01-19 08:01

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

if ( aAnim ) {
    [UIView beginAnimations:nil context:CFBridgingRetain([NSNumber numberWithInt:aOff         


        
相关标签:
1条回答
  • 2021-01-19 08:36

    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;
    
    0 讨论(0)
提交回复
热议问题