Skip to content

Instantly share code, notes, and snippets.

@apparentsoft
Last active December 26, 2015 09:09
Show Gist options
  • Save apparentsoft/7126853 to your computer and use it in GitHub Desktop.
Save apparentsoft/7126853 to your computer and use it in GitHub Desktop.
I think I found a stupid bug in NSURL when trying to read Mavericks Tags associated with the URL, along with other information for that URL resources.
The output for the code below is as following, on my Mac. So, the first time that I ask to read the Tags it won't return localized filename or the UTI. But it will on a next invocation of the same code. Duh!
2013-10-24 00:10:26.780 Untitled 3[39076:507] Attributes WITHOUT Tags: {
NSURLContentAccessDateKey = "2013-10-23 12:38:49 +0000";
NSURLContentModificationDateKey = "2013-10-23 10:33:50 +0000";
NSURLLocalizedNameKey = Applications;
NSURLTypeIdentifierKey = "public.folder";
}
2013-10-24 00:10:26.781 Untitled 3[39076:507] Attributes WITH Tags: {
NSURLContentAccessDateKey = "2013-10-23 12:38:49 +0000";
NSURLContentModificationDateKey = "2013-10-23 10:33:50 +0000";
}
2013-10-24 00:10:26.781 Untitled 3[39076:507] Attributes WITH Tags AGAIN: {
NSURLContentAccessDateKey = "2013-10-23 12:38:49 +0000";
NSURLContentModificationDateKey = "2013-10-23 10:33:50 +0000";
NSURLLocalizedNameKey = Applications;
NSURLTypeIdentifierKey = "public.folder";
}
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
NSURL *url = [NSURL fileURLWithPath:@"/Applications"];
NSDictionary *attrWithoutTags = [url resourceValuesForKeys:@[NSURLLocalizedNameKey, NSURLContentModificationDateKey, NSURLContentAccessDateKey, NSURLTypeIdentifierKey] error:NULL];
NSDictionary *attrWithTags = [url resourceValuesForKeys:@[NSURLLocalizedNameKey, NSURLContentModificationDateKey, NSURLContentAccessDateKey, NSURLTypeIdentifierKey, NSURLTagNamesKey] error:NULL];
NSDictionary *attrWithTagsAgain = [url resourceValuesForKeys:@[NSURLLocalizedNameKey, NSURLContentModificationDateKey, NSURLContentAccessDateKey, NSURLTypeIdentifierKey, NSURLTagNamesKey] error:NULL];
NSLog(@"Attributes WITHOUT Tags: %@", attrWithoutTags);
NSLog(@"Attributes WITH Tags: %@", attrWithTags);
NSLog(@"Attributes WITH Tags AGAIN: %@", attrWithTagsAgain);
[p release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment