1

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • I wouldn't be 100% sure of what its called since I've never given it too much thought, but what you're doing there is creating a temporary object. The result of the function call [self createArray] is not stored, so the NSArray is temporary. Please correct me if I am wrong. – Alejandro Jan 09 '14 at 20:22
  • You are just directly taking the return value of the function and using it. JQuery has chaining built into most of their calls. I don't know if that is the official term for that sort of thing. – 0xFADE Jan 09 '14 at 20:30
  • @JoshCaswell Sorry, I didn't even know how to call this in order to search for a solution. And the search term "square-bracketed index after an Array" didn't not formulate / fabricate in my mind / imagination as well as it did for the other author linked. Thanks everyone for the time. – Unheilig Jan 09 '14 at 20:31
  • 1
    No need to apologize; searching for terminology is indeed hard. – jscs Jan 09 '14 at 20:31

1 Answers1

0

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

rob mayoff
  • 375,296
  • 67
  • 796
  • 848