pass objective c object and primitive type into a void *

Posted by user674669 on Stack Overflow See other posts from Stack Overflow or by user674669
Published on 2012-06-23T20:29:49Z Indexed on 2012/06/23 21:16 UTC
Read the original article Hit count: 342

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios