0

I have the following code - note it has to objects with temp, but I will explain.

NSString *temp =  _passedOnURL;
NSString *temp = @"http://google.com"; //I comment the one out that I do not use.

NSLog(@"TEMP - %@", temp);

NSURL *feedURL = [NSURL URLWithString:temp];
NSLog(@"FEED URL - %@", feedURL);

The _passedOnURL is a string with the contents passed from a Segue.

Now when I use the 1st temp, the FEED URL returns (null), but when I Log Temp it is still there, so somehow the NSURL does not read the string.

When I hardcode the string with the second temp - there is no issue.

In my mind there is no difference for the NSURL when it is reading the NSString yet, it seems to behave different.

Is there any reason for this??

EDIT

When I do the following code I have no issues:

_passedOnURL = @"http://www.google.com";

so I really have no explanation for this???

jwknz
  • 6,598
  • 16
  • 72
  • 115

4 Answers4

2

It seems you have an invalid url string stored in temp. Not every string can be converted to a url but the valid url. Invalid chars and format will lead a nil object after +URLWithString:. So would you let us know what is stored in temp when you try this?

onevcat
  • 4,591
  • 1
  • 25
  • 31
2

try escaping it : [NSURL URLWithString: [temp stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]]

bert
  • 1,556
  • 13
  • 15
1

According to the doc for URLWithString:

Parameters
URLString

The string with which to initialize the NSURL object. Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808.

Return Value

An NSURL object initialized with URLString. If the string was malformed, returns nil.

So my guess is that your _passedOnURL is not a valid URL.

Pang
  • 9,564
  • 146
  • 81
  • 122
0

I would do a NSLog on your _passedOnURL to check if you are getting the string correctly from the other segue.