Vishal Singh
Vishal Singh

Reputation: 4480

NSURL object not an Objective-C object

I am trying to make a URL with a string using the following code

NSString *urlStr = [NSString stringWithFormat:@"http://demo.com"];
NSURL *url = [NSURL urlWithString:urlStr];

But the URL is always coming up nil. When I print description of the URL, I get:

Printing description of url:(NSURL *) url = 0xbfffdb78 (not an Objective-C object)

Can anyone help me and what am I missing?

Upvotes: 0

Views: 1089

Answers (2)

btmanikandan
btmanikandan

Reputation: 1931

Try this,

      NSString *urlstr=[NSString stringWithFormat:@"http://google.com"];

      urlstr = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

      NSURL * url=[NSURL URLWithString:urlstr];

Upvotes: 2

AppleDelegate
AppleDelegate

Reputation: 4249

The description of NSURL or NSMutableURL shall be printed in this way

  NSLog(@"%@",url.absoluteString);

Upvotes: 0

Related Questions