Question

[CATransaction withAnimationSpeed:1.0 :^ {
            if(newMultiplier > 100)
                fillLayer.backgroundColor = ColRGBA(1, 1, 0, 0.2);
            else
                fillLayer.backgroundColor = ColRGBA(0, 0, 0, 0);
        }];

^{}mean? why use this symbol.

Was it helpful?

Solution

That is called a block. They're similar to anonymous functions in other languages, in that you use them to run code blocks as part of some other routine (in your case, animation). Blocks are useful when you don't want to create one-use methods in your class just so you can pass their selectors to Objective-C methods like performSelector:.

^ is the symbol for a block. The code within the { } behaves just like the code in a method's { } block.

Some blocks have parameters, specified similarly to C functions:

^(int a, int b) {
    NSLog(@"a + b = %d", a + b);
}

In your given code, ^ {} is the same as ^(void) {}, i.e. the block doesn't take any parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top