views:

12

answers:

1

Hi,

This is a simple and basics but I had a doubt that if it is declared globally with out initial value what happens ?

NSURL *finalURL; // here i need to initial value as nil if it is like this NSURL *finalURL=@""; giving warning.

nssarry *array=nil; // is this correct.

Please give the reply, Thank You, Madan Mohan.

A: 

It should be static NSURL *finalURL = nil; and you have to define that inside a method. Then you can check if finalURL == nil and init it.

- (void)method
{
    static NSURL *url = nil;
    if(url == nil) {
        url = [[NSURL urlWithString:@"http://host"] retain];
    }
}

You can't do NSURL *finalURL = @"" because @"" is a String and not an NSURL!

NSArray *array = nil; is only correct if you capitalize NSArray correct!

V1ru8