Re: Is This Right?
Re: Is This Right?
- Subject: Re: Is This Right?
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 5 Jun 2001 18:58:58 -0700
On Tuesday, June 5, 2001, at 01:10 PM, Don Arbow wrote:
Do I understand this right? Can these two lines of code:
NSMutableArray *myArray;
myArray = [[NSMutableArray alloc] init];
be combined thus:
NSMutableArray *myArray = [[NSMutableArray alloc] init];
Sure, the C language allows you to combine a variable declaration with
an
initializer. The above is just as valid as this:
int myVar = 5;
But make sure that all of your declarations are at the top of the
function.
Well, to be precise, they have to be at the beginning of a block, not
necessarily at the beginning of a function or method. Personally, I
like to declare variables as closely as possible to where they're first
used.
E.g:
- (void) foo: bar
{
if (bar)
{
int bas = [bar intValue]; // <- legal, though not at the beginning of
the method!
// and so on..
}
}
-jcr
"Scientology is both immoral and socially obnoxious... it is
corrupt, sinister and dangerous." - Mr. Justice Latey, London 1984