Tuesday, December 11, 2012

NSURL Path Handling

Mike Abdullah:

So the end result here is that if you need to remove the last path component of a URL and stand a chance of being passed in one ending in two or more slashes you’re kinda stuck.

I’ve always thought it a good idea to standardize paths and URLs, to get rid of any . or .. components. Otherwise, trying to get the filename or the container URL may give an unexpected result. But this example shows that sometimes even that isn’t enough. NSURLs are better than NSStrings, but in my view Cocoa still doesn’t handle file stuff properly.

1 Comment RSS · Twitter

For this specific case, wouldn't a better workaround be something like:

while [fooURL hasSuffix:@"//"]
trim last character

?

cl

Leave a Comment