0

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?

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Vishal Singh
  • 4,400
  • 4
  • 27
  • 43

2 Answers2

2

Try this,

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

      urlstr = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

      NSURL * url=[NSURL URLWithString:urlstr];
Popeye
  • 11,839
  • 9
  • 58
  • 91
btmanikandan
  • 1,923
  • 2
  • 25
  • 45
0

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

  NSLog(@"%@",url.absoluteString);
AppleDelegate
  • 4,269
  • 1
  • 20
  • 27