Skip to content

Instantly share code, notes, and snippets.

@bryanluby
Created February 1, 2014 17:23
Show Gist options
  • Save bryanluby/8755479 to your computer and use it in GitHub Desktop.
Save bryanluby/8755479 to your computer and use it in GitHub Desktop.
NSURL category to get and set Finder tags.
//
// NSURL+Tags.h
//
// Created by Bryan Luby on 10/23/13.
// Copyright (c) 2013 Bryan Luby. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSURL (Tags)
- (NSArray *)bjl_tags;
- (void)bjl_setTags:(NSArray *)newTags;
@end
//
// NSURL+Tags.m
//
// Created by Bryan Luby on 10/23/13.
// Copyright (c) 2013 Bryan Luby. All rights reserved.
//
#import "NSURL+Tags.h"
@implementation NSURL (Tags)
- (void)bjl_setTags:(NSArray *)newTags
{
NSError *setTagError = nil;
BOOL success = [self setResourceValue:newTags
forKey:NSURLTagNamesKey
error:&setTagError];
if (!success) {
NSLog(@"Error: %@", [setTagError localizedDescription]);
}
}
- (NSArray *)bjl_tags
{
NSArray *currentTags = nil;
NSError *getTagError = nil;
BOOL success = [self getResourceValue:&currentTags
forKey:NSURLTagNamesKey
error:&getTagError];
if (success) {
return currentTags;
} else {
NSLog(@"Error: %@", [getTagError localizedDescription]);
return nil;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment