views:

19

answers:

1

I'm doing some UIView animation stuff using

[UIView beginAnimations:nil context:nil];
// ... Animation configuration ...
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationEnded:finished:context:)];
[UIView commitAnimations];

Regarding the following question: http://stackoverflow.com/questions/3455604/apple-rejected-app-because-of-animationdidstopfinishedcontext-is-a-non-public

I implemented my own method as the "setAnimationDidStopSelector".

My question is regarding the context:(void *)context parameter. Apple defines it as follow :

Additional application-supplied information that is passed to the animation delegate messages—the selectors set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.

I'm wondering what king of thing can be passed in as a context. I'm relatively new to Objective-C and C programming and a bit lost with the void* type.

Can we pass in any sort of argument, objects, NSDictionnary, NSString, etc.

Thanks

+2  A: 

void * is a pointer to anything. You can pass a pointer to any object or to other stuff such as a struct or a Core Foundation opaque type. To get rid of the compiler warning, cast the pointer to void *:

... context:(void *)myDictionary];

Be aware that the method has no idea what context contains and thus will not retain it or otherwise care for correct memory managemnet. You have to ensure that the thing you pass to context still exists when the animation delegate methods are called.

Ole Begemann
Ok thanks for your answer, this sounds clear and I just found this question http://stackoverflow.com/questions/1304176/objective-c-difference-between-id-and-void/1304277#1304277
jchatard