pass objective c object and primitive type into a void *
- by user674669
I want to pass 2 variables:
UIImage * img
int i
into another method that only takes a (void *)
I tried making a C struct containing both img and i
struct MyStruct {
UIImage *img;
int i;
}
but xcode gives me an error saying "ARC forbids Objective-C objects in structs or unions"
The next thing I tried is to write an objective-c class MyStruct2 containing img and i, alloc-initing an instance of it and typecasting it as (__bridge void*) before passing it to the method. Seems little involved for my use case. Seems like there should be a better way.
What's the simplest way to achieve this?
Thank you.
Edit based on comments: I have to use void * as it is required by the UIView API. I created a selector as mentioned by UIVIew API
+ (void)setAnimationDidStopSelector:(SEL)selector
Please see documentation for setAnimationDidStopSelector at http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html . It says ... The selector should be of the form:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
I want to pass both img and i into the (void *)context argument.