Technical term for accessing an array with an index and square brackets

809 Views Asked by At

What is the term or name of the operation for getting member of an array? For example, this method returns a simple array:

- (NSArray*)createArray
{
    NSArray *myArray = [[NSArray alloc] initWithObjects:@"unordentliches array", @"beliebiges Value", nil];
    return myArray;
}

And I can NSLog one of its elements in the following way:

NSLog(@"%@", [self createArray][1]);

Output:

beliebiges Value

Good, no problem here.

But what do we call this operation: [self createArray][1]? One that allows us to -- without first assigning the value to a NSString -- simply put this [1] right next to the the returned value from a method call and output the value?

[self createArray][1];

What is the technical term for this?

1

There are 1 best solutions below

0
On BEST ANSWER

Putting the element index in parentheses (or brackets in this case) after an array is called “subscripting”. The index is called a “subscript”.

There is no special name for directly subscripting the array returned by a message without storing the array in a variable first.

Under the covers, the compiler turns the subscripting into another message, like this:

[[self createArray] objectAtIndexedSubscript:1];

Sending a message directly to the object returned by another message is called “message chaining” or “method chaining”.