Declaration of locationManager


#1

Just a question :
in the book, locationManager was declared this way :

Is it the same as this ?

Thanks
Fred


#2

[quote]Just a question :
in the book, locationManager was declared this way :
locationManager = [[CLLocationManager alloc]init];
[/quote]
locationManager = [[CLLocationManager alloc]init];
This is not a declaration statement; it is an assignment statement. So there must be somewhere a declaration/definition (visible in the current scope) of locationManager variable before this statement.

For example:


- (void)fooBar
{
CLLocationManager *locationManager;
...
locationManager = [[CLLocationManager alloc]init];
...
}

Or:


- (void)fooBar
{
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
...
locationManager = [[CLLocationManager alloc]init];
...
}

Or:

CLLocationManager *locationManager;

- (void)fooBar
{
...
locationManager = [[CLLocationManager alloc]init];
...
}

(In above code fragments) whatever is in the (old) locationManager variable, the assignment statement is wiping it out with a new one.

[quote]Is it the same as this ?
CLLocationManager *locationManager = [[CLLocationManager alloc]init];[/quote]
No.

Because here locationManager variable is being declared and assigned to (or initialised) at the same time. (A new variable is being created.)
It is equivalent to this:

CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc]init];

#3

Thanks a lot for your answer (and for your time) !
It takes some time to get accustomed to the logic, but it does make sense.

Fred