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
votes
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);
...
}