I am beginner in Objective-C, I saw many examples on Obj-C language, using ^ simbol. Can anyone tell me what is the use of ^ in Obj-C. If you give me an example then it will be very helpful for me. Thanks.
^ is called as "Caret". In Objective C, ^ operator is used to declare a block variable and also used to indicate the beginning of a block literal, the body of block is contained within { } (curly braces). Here is an example with its explanation:
int num1 = 10; int (^abcBlock)(int) = ^(int num2) {
return num2 * num1;
}
in this example- Block-name is abcBlock and the return-type of abcBlock is int, the abcBlock has an argument which is also an int. now, next to the assignment(=) operator, the code ^(int num2) { return num2 * num1; } is a literalblock definition having num2 as an abcBlock argument-name, and the code between the { } curly braces is used as the body of the abcBlock.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
^ is called as "Caret". In Objective C, ^ operator is used to declare a block variable and also used to indicate the beginning of a block literal, the body of block is contained within { } (curly braces).
Here is an example with its explanation:
in this example- Block-name is abcBlock and the return-type of abcBlock is int, the abcBlock has an argument which is also an int.
now, next to the assignment(=) operator, the code ^(int num2) { return num2 * num1; } is a literal block definition having num2 as an abcBlock argument-name, and the code between the { } curly braces is used as the body of the abcBlock.