Re: Properly comparing file NSURLs for equality?
Re: Properly comparing file NSURLs for equality?
- Subject: Re: Properly comparing file NSURLs for equality?
- From: Lee Ann Rucker <email@hidden>
- Date: Fri, 27 May 2011 17:34:20 -0700
On May 27, 2011, at 5:06 PM, Mike Abdullah wrote:
> It is a bit of a knotty problem. I've ended up with:
>
> - (BOOL)ks_isEqualToURL:(NSURL *)otherURL;
> {
> BOOL result = [self isEqual:otherURL];
>
> // For file: URLs the default check might have failed because they reference the host differently. If so, fall back to checking paths
> if (!result && [self isFileURL] && [otherURL isFileURL])
> {
> result = [[self path] isEqualToString:[otherURL path]];
> }
>
> return result;
> }
That can fail in the circumstances from my code's comment:
/*
* [NSURL isEqualTo:] fails when a path has a trailing slash and
* an otherwise matching one doesn't. Standardize the path first
* and use localizedCompare in case the characters were composited differently.
*/
if ([[[self path] stringByStandardizingPath]
localizedCompare:[[inURL path] stringByStandardizingPath]] == NSOrderedSame) {
return YES;
}
_______________________________________________
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