The UIView class has a class method:
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
It’s the first time I’ve seen an argument like the animation and completion arguments. What do I write in this place:animations:(void (^)(void))animations ? What does (^) and void mean?
What your are seeing there is Objective-C’s block syntax. The syntax is completely obtuse, frustrating, and mind-numbing, but what it is doing is actually very simple.
A block is logically equivalent to a closure in other languages such as JavaScript, so ignoring the nasty syntax you can think of the signature being something along the lines of:
…where
animationFunctionandonCompleteare closures (or blocks, to use the Objective-C parlance). Basically you can think of them as function pointers that preserve the state of the context in which they are created.Anyhow, the
(^)token in Objective-C simply denotes a block. The type that precedes it denotes the return-type of the block (sovoidin your example, meaning that neither block returns a value), and the types that follow it in parenthesis denote any arguments that the block takes (so none foranimations, and aBOOLcalled ‘finished’ for thecompletionblock.