Can anyone help me with the seemingly simple task of creating a relative NSURL 
for a filesystem object? The catch here (sorry!) is that I really do need 
backward compatibility to 10.7, which rules out 
fileURLWithFileSystemRepresentation:isDirectory:relativeToURL: (which I suspect 
is the “right” way of doing this).

My attempt like:
[NSURL URLWithString:[path 
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding] 
relativeToURL:relativeTo];

This had been working ok for some time, but I have just found it to be broken 
for filenames containing unusual characters. In particular, it fails when given 
a filename containing a “smart quote” (not easily created directly with the 
keyboard, but auto-generated as part of a time machine backup, based on the 
machine name).

Although I do not recall why I used stringByAddingPercentEscapesUsingEncoding, 
I think it must have been because it failed on some other filename pattern if I 
did not do that.

String encodings is something I know basically nothing about, I am afraid. I am 
speculating that what is happening is that the fancy apostrophe is not ASCII 
and so my code does not work for that filename. I can change the encoding to 
NSUnicodeStringEncoding, and things seem ok, but I don’t know whether that will 
now definitely work for all filenames, or whether I have just stored up an even 
more obscure problem for the future.

So, finally getting to two actual questions:
1. Will unicode encoding give me a robust solution here?
2. Is there a differnet, better way (pre-10.9) I should be using to create a 
relative URL?

Thanks for any advice
Jonny.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to