Re: Correct way to specify anchors with NSURL?
Re: Correct way to specify anchors with NSURL?
- Subject: Re: Correct way to specify anchors with NSURL?
- From: Jens Alfke <email@hidden>
- Date: Thu, 21 Apr 2016 09:11:42 -0700
> On Apr 20, 2016, at 10:16 PM, Graham Cox <email@hidden> wrote:
>
> Annoying that the ‘fragment’ property of NSURL is read-only, that looks like an obvious way to do it, if the API was sane.
The API is sane. NSURLs are immutable, just like NSStrings and many other Foundation classes.
NSURLComponents basically plays the role of an “NSMutableURL”. In the past, before that class was available, I’d manipulate the URL string directly. Yes, it’s a pain; that’s why they added NSURLComponents (but I wish they’d done so earlier!)
> It strikes me that it’s a bug that URLByAppendingPathComponent: doesn’t parse for a fragment just as -initWithString: does though, the anchor/fragment is a perfectly reasonable part of a path
No, it’s not. It’s an entirely separate component of the URL. (You can read the relevant RFC if you want the gory details.)
Consider also that it’s perfectly valid for a path to contain a “#” character, especially since URLs are so frequently used for filesystem paths. If appending a path component treated “#” literally, without escaping, then using URLs for filesystem paths would break whenever the caller ran into a file or directory name that contained a “#” character.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden