1

I'm trying to build a NSURL from a string like this :

NSString *urlString = self.providerData[@"LogoUrl"];

NSURL *url = [NSURL URLWithString:urlString];

NSLog(@"logo url string : %@ - logo url : %@", urlString, url);

Here's the output :

logo url string :  http://cdn.site-annonce.fr/img/mobile/multipublish/TopAnnonces.png - logo url : (null)

The doc says it can return nil if the URL is malformed. What am I missing ?

2 Answers 2

2

If we take the output literally, there's leading whitespace (two blanks) even though the format string contains only one.

Fix with :

urlString = [urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Sign up to request clarification or add additional context in comments.

1 Comment

jeez! I really missed it
1

When you copy & paste the log results and the source code, you have a leading space in your URL.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.