Why we use ^ Symbol in Objective-C?

Total Post:101

 1035  View(s)
Rate this:
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.
  1. Post:214

    Re: Why we use ^ Symbol in Objective-C?

    ^ 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 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.

      Modified On Dec-18-2015 01:23:05 AM