ArcticMonkey ArcticMonkey - 3 months ago 15
Objective-C Question

What is the difference between square brackets and curly brackets in Objective-C?

I am new to Objective-C and can not understand the difference in using curly brackets and square brackets for arrays? For example below code

float trainingData[3][3] = { { 84, 191, 19 }, { 24, 186, 17}, { 22, 157, 21} };

Answer

In C:

Square Bracket: It represent that it is an Array.

In your given code trainingData[3][3] represent the a 2D Array with 3 row and 3 column.

Curly Bracket: Multidimensional arrays may be initialized by specifying bracketed values for each row. In your Given code:

float trainingData[3][3] = { 
{ 84, 191, 19 },       /*  initializers for row indexed by 0 */
{ 24, 186, 17},         /*  initializers for row indexed by 1 */
{ 22, 157, 21}          /*  initializers for row indexed by 2 */
};

In Objective C:

Square Bracket:

the square bracket syntax use for all of method calls. you use the dot syntax when you're using getters and setters.

Curly Bracket: It Represent the dictionary or mutable dictionary.

NSDictionary *Dic= @{@"Name":@"abc",@"ID":@"123"};
Comments