开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜