StefanHanotin
StefanHanotin

Reputation: 301

NSURL is nil when using NSDate

I have an NSURL which contains a URL and a variable that is an NSDate:

NSURL *url = [[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.googlebio.com/xml_test.aspx?date=%@",self.storeDate]] autorelease];

I also tried it this way but to no avail:

NSString*string = [NSString stringWithFormat:@"http://www.googlebio.com/xml_test.aspx?date=%@",self.storeDate];

    NSURL*url=[NSURL URLWithString:string];
    [url autorelease];

The application does not crash but when I debug it, url is nil.

Any ideas as to why this is?

Thanks.

Stefan.

Upvotes: 1

Views: 457

Answers (1)

coneybeare
coneybeare

Reputation: 33101

If your date is in a format that NSURL will be confused by, then it will be nil. Make sure you urlencode your date, or represent it in a way that is a legitimate URL. Look into this:

[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

Perhaps if you put a debug statement of your url string, I can help further

Upvotes: 2

Related Questions