1
votes

LooK this method: beginAnimations:context: This is a method of class UIView. The context need parameter which is a type of void-pointer,and I need to send a UIImageView to context. I get a warning,which says void* has been forbidden when I use ARC. So how can I send UIImageView to context except not use ARC.

1
Use UIView's block animation methods. It's more convenient because you don't neet an animation completion delegate somewhere else.Nicolas Miari
Plus the docs say to use the block animation methods.Jack Lawrence
Thanks for help.I will learn to use UIView's block animation methods.Sky Dragon

1 Answers

0
votes

The comments above provided the correct answer for this particular case (use the block-based animation methods) but in general if you have an API which takes a context void * and you'd like to pass an object, I find it best to convert your id to a CFTypeRef so you can get manual memory management semantics on the pointer (CFTypeRef is a typedef for void *), etc. Note however that this requires that the callback must be called in order to get your object released (i.e. converted back to ARC's built-in management).

Here's an example for some imaginary API I just dreamt up:

- (void) doSomethingWithObject: (id) object {
    // use CFBridgingRetain() to turn object into a manually-retained CFTypeRef/void*
    [someObject performBackgroundTaskWithTarget: self
                                       selector: @selector(bgTask:)
                                        context: CFBridgingRetain(object)];
}

- (void) bgTask: (void *) context
{
    // use CFBridgingRelease() to turn our void*/CFTypeRef into an ARC-managed id
    id object = CFBridgingRelease((CFTypeRef)context);
    ...
}