[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Accessing array members without the use of objectAtIndex
From: |
Richard Frith-Macdonald |
Subject: |
Re: Accessing array members without the use of objectAtIndex |
Date: |
Sun, 15 Apr 2018 09:38:58 +0100 |
> On 14 Apr 2018, at 13:46, David Chisnall <gnustep@theravensnest.org> wrote:
>
> Hi Tyler,
>
>> On 14 Apr 2018, at 00:03, tyler mclean <sonarsoundapplications@gmail.com>
>> wrote:
>>
>> Greetings developers,
>>
>> I want to preface this question by saying that this project is
>> impressive. My question is, is there a way to access members of
>> NSArray or NSMutableArray like an array with the GNUstep framework or
>> is that a function that currently only sits with the current Apple
>> architecture of the language/libraries?
>>
>> e.g
>> NSMutableArray *myArray = [[NSMutableArray alloc] init]; //This will
>> be an array of NSStrings
>> . . .
>> NSLog(@"%@", myArray[0]);
>>
>> instead of
>>
>> NSLog(@"%@", [myArray objectAtIndex:0]);
>>
>> while this particular example does not create much bloat, repeated
>> need to access members can make code substantially larger than that of
>> it's counterpart on Apple's end. If so, what do I need to do to start
>> using this feature. Else if not, is there a plan to add this in the
>> (hopefully near) future?
>
> Your post reminds me why I hate the new syntax - it will generate exactly the
> same amount of code as the traditional syntax, yet gives the superficial
> impression of being more efficient. As with the property accessor syntax, it
> generates a message send using the same syntax that C uses for a simple
> pointer arithmetic operation.
I agree with this ... the fact that we support this syntax does not mean that
anyone should use it.
If you use the -objectAtIndex: method your code is clearer and more
maintainable (minimising the chance of confusing C array variables and NSArray
variables) as well as being marginally more efficient and substantially more
portable.