Madan Mohan
Madan Mohan

Reputation: 8810

How to declare the nsurl variable with inital value as nil and also for nsarray?

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.

Upvotes: 0

Views: 1948

Answers (1)

V1ru8
V1ru8

Reputation: 6147

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!

Upvotes: 0

Related Questions