NSURL is null while NSString is correct in Objective-C
问题 I have an NSString containing a url and when I allocate NSURL with the NSString , NSURL outputs (null). It's because there are some illegal characters in the url, which NSURL can't read without encoding the NSString containing the url. NSString *u = [incomingUrlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:u]; NSLog(@"INCOMINGURLSTRING: %@" , u); NSLog(@"URL: %@" , url); Output is: INCOMINGURLSTRING: /url/path/fileName_blå.pdf URL