Does any kind of optimizing effect declare a variable outside the loop in Objective-C?

I got the habit of declaring reusable variables outside of loops from working in other languages, for example:

NSString *lcword;
for( NSString *word in tokens )
{
    lcword = [ word lowercaseString ];
    ...    
}

Is it wise to do this in Objective-C, or is the compiler smart enough to make it unnecessary?

+5
source share
2 answers

There is no benefit in Objective-C that I know of. AFAIK, every modern Objective-C compiler allocates stack space for local variables at the beginning of a function or method. Defining a variable in a loop simply does not allow the name to be used outside the loop and does not allow the compiler to reuse the stack space if it wants.

. : ? (++) ( , , )

+9

, . , .

0

All Articles