Reputation: 6822
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???
Upvotes: 0
Views: 204
Reputation: 1596
try escaping it : [NSURL URLWithString: [temp stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]]
Upvotes: 2
Reputation: 4631
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?
Upvotes: 2
Reputation: 10111
According to the doc for URLWithString:
Parameters
URLStringThe 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.
Upvotes: 1
Reputation: 1
I would do a NSLog on your _passedOnURL to check if you are getting the string correctly from the other segue.
Upvotes: 0