The result of this code is that url is null
NSString* home = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/"];
NSURL *url = [NSURL URLWithString:home];
and so is this:
NSString* home = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/"];
home = [home stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:home];
Your question is not about creating an URL from a string containing spaces, but from a path string containing spaces.
For a path, you should not use
URLWithString. Mac OS X and iOS include convenience functions for building NSURLs for file paths that handle this and more for you automatically. Use one of them instead.Apple’s documentation for
[NSURL fileURLWithPath: path]says:Also, you should be using
NSSearchPathForDirectoriesInDomainsto find the Application Support directory.Putting this all together, you’d end up with something like this:
Source: