WHY WE USE ^ SYMBOL IN OBJECTIVE-C?

Pravesh Singh

Total Post:101

Points:709
Posted by  Pravesh Singh
 717  View(s)
Ratings:
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.
Thanks.
  1. Tarun Kumar

    Post:214

    Points:1642
    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!