Last active
December 27, 2015 04:39
-
-
Save bdbergeron/7268243 to your computer and use it in GitHub Desktop.
Get a nicely formatted filename for an ALAsset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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