Skip to content

Instantly share code, notes, and snippets.

@bdbergeron
Last active December 27, 2015 04:39
Show Gist options
  • Save bdbergeron/7268243 to your computer and use it in GitHub Desktop.
Save bdbergeron/7268243 to your computer and use it in GitHub Desktop.
Get a nicely formatted filename for an ALAsset
- (NSDateFormatter *)syncDateFormatter
{
static NSDateFormatter *_syncDateFormatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_syncDateFormatter = [NSDateFormatter new];
_syncDateFormatter.dateFormat = @"yyyy-MM-dd HH.mm.ss";
_syncDateFormatter.locale = [NSLocale currentLocale];
});
return _syncDateFormatter;
}
- (NSString *)filenameForAsset:(ALAsset *)asset
{
NSDate *itemDate = [asset valueForProperty:ALAssetPropertyDate];
NSURL *itemURL = [[asset defaultRepresentation] url];
NSString *itemExtension = [itemURL dictionaryFromQueryString][@"ext"];
return [NSString stringWithFormat:@"%@.%@", [[self syncDateFormatter] stringFromDate:itemDate], itemExtension.lowercaseString];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment